Skip to content

Commit

Permalink
Fixing the local server and config.json bug (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
sansyrox authored and hongquan committed Sep 9, 2018
1 parent 9dd2264 commit 65d43e0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions access_point/server/server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
""" This script creates a light flask server to allow the Smart Speaker to connect with the external clients.
The endpoints will be hit through the mobile clients in the following order (SYNCHRONOUSLY):
1.Room Name
2.Wifi Credentials
3.Authentication
4. Configuration (/config)
"""

from flask import Flask , render_template , request
from flask import jsonify
import subprocess # nosec #pylint-disable type: ignore
Expand All @@ -6,7 +15,8 @@

access_point_folder = os.path.dirname(os.path.abspath(__file__))
wifi_search_folder = os.path.join(access_point_folder, '..')
config_json_folder = os.path.join(access_point_folder, '../config.json')
config_json_folder = os.path.join(access_point_folder, '../../')
config_json_file = os.path.join(access_point_folder, '../../config.json')
configuration_script = os.path.join(access_point_folder, '../../config_generator.py')
authentication_script = os.path.join(access_point_folder, '../../authentication.py')

Expand All @@ -26,6 +36,7 @@ def config():
tts = request.args.get('tts')
hotword = request.args.get('hotword')
wake = request.args.get('wake')
os.chdir(config_json_folder)
subprocess.Popen(['sudo', 'python3', configuration_script, stt, tts, hotword, wake]) #nosec #pylint-disable type: ignore
subprocess.call(['sudo', 'systemctl', 'daemon-reload']) #nosec #pylint-disable type: ignore
subprocess.call(['sudo', 'systemctl', 'disable', 'ss-python-flask.service']) #nosec #pylint-disable type: ignore
Expand All @@ -41,6 +52,7 @@ def login():
auth = request.args.get('auth')
email = request.args.get('email')
password = request.args.get('password')
os.chdir(config_json_folder)
subprocess.call(['sudo', 'python3', authentication_script, auth, email, password]) #nosec #pylint-disable type: ignore
display_message = {"authentication":"successful", "auth": auth, "email": email, "password": password}
resp = jsonify(display_message)
Expand All @@ -51,6 +63,7 @@ def login():
def wifi_config():
wifi_ssid = request.args.get('wifissid')
wifi_password = request.args.get('wifipassd')
os.chdir(config_json_folder)
subprocess.call(['sudo', 'bash', wifi_search_folder + '/wifi_search.sh', wifi_ssid, wifi_password]) #nosec #pylint-disable type: ignore
display_message = {"wifi":"configured", "wifi_ssid":wifi_ssid, "wifi_password": wifi_password}
resp = jsonify(display_message)
Expand All @@ -60,7 +73,7 @@ def wifi_config():
@app.route('/speaker_config', methods=['GET'])
def speaker_config():
room_name = request.args.get('room_name')
config = json_config.connect(config_json_folder)
config = json_config.connect(config_json_file)
config['room_name'] = room_name
display_message = {"room_name":room_name}
resp = jsonify(display_message)
Expand Down

0 comments on commit 65d43e0

Please sign in to comment.