diff --git a/src/Python/flask/web/app.py b/src/Python/flask/web/app.py index 4cedb6c..10b896b 100644 --- a/src/Python/flask/web/app.py +++ b/src/Python/flask/web/app.py @@ -3,11 +3,18 @@ import paho.mqtt.client as mqtt app = Flask(__name__) +def on_message(client, userdata, message): + global kobuki_message #set scope for this variable + kobuki_message = str(message.payload.decode("utf-8")) + # Create an MQTT client instance mqtt_client = mqtt.Client() mqtt_client.username_pw_set("ishak", "kobuki") -mqtt_client.connect("localhost", 1883, 60) +mqtt_client.connect("145.92.224.21", 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 + @app.route('/', methods=["GET","POST"]) def index(): @@ -27,10 +34,10 @@ def move(): @app.route('/data', methods=['GET']) def data(): - data = 0 - data = mqtt_client.subscribe("kobuki/data") - if data != 0: - return jsonify({data}) + return jsonify({"kobuki_message": kobuki_message}) + + + if __name__ == '__main__': app.run(debug=True) \ No newline at end of file