diff --git a/src/Python/flask/web/app.py b/src/Python/flask/web/app.py index d92d5b0..a125737 100644 --- a/src/Python/flask/web/app.py +++ b/src/Python/flask/web/app.py @@ -2,7 +2,7 @@ from flask import Flask, request, render_template, jsonify import paho.mqtt.client as mqtt app = Flask(__name__) -# This function gets triggered when it receives a mqtt message + def on_message(client, userdata, message): global kobuki_message #set scope for this variable kobuki_message = str(message.payload.decode("utf-8")) @@ -10,7 +10,7 @@ def on_message(client, userdata, message): # Create an MQTT client instance mqtt_client = mqtt.Client() mqtt_client.username_pw_set("ishak", "kobuki") -mqtt_client.connect("145.92.224.21", 1883, 60) +mqtt_client.connect("localhost", 1883, 60) mqtt_client.loop_start() mqtt_client.subscribe("kobuki/data") mqtt_client.on_message = on_message # this lines needs to be under the function definition otherwise it cant find which function it needs to use @@ -18,7 +18,10 @@ mqtt_client.on_message = on_message # this lines needs to be under the function @app.route('/', methods=["GET","POST"]) def index(): - return render_template('index.html') + if request.authorization and request.authorization.username == 'ishak' and request.authorization.password == 'kobuki': + return render_template('index.html') + else: + return ('Unauthorized', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'}) @app.route('/move', methods=['POST']) def move(): @@ -40,4 +43,4 @@ def data(): if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file + app.run(debug=True, port=5000) diff --git a/src/Python/flask/web/templates/index.html b/src/Python/flask/web/templates/index.html index e5e26ef..519402f 100644 --- a/src/Python/flask/web/templates/index.html +++ b/src/Python/flask/web/templates/index.html @@ -29,7 +29,7 @@

Sensor Data

- +
Sensor