mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
made working endpoint for kobuki data
This commit is contained in:
@@ -3,11 +3,18 @@ import paho.mqtt.client as mqtt
|
|||||||
|
|
||||||
app = Flask(__name__)
|
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
|
# Create an MQTT client instance
|
||||||
mqtt_client = mqtt.Client()
|
mqtt_client = mqtt.Client()
|
||||||
mqtt_client.username_pw_set("ishak", "kobuki")
|
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.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"])
|
@app.route('/', methods=["GET","POST"])
|
||||||
def index():
|
def index():
|
||||||
@@ -27,10 +34,10 @@ def move():
|
|||||||
|
|
||||||
@app.route('/data', methods=['GET'])
|
@app.route('/data', methods=['GET'])
|
||||||
def data():
|
def data():
|
||||||
data = 0
|
return jsonify({"kobuki_message": kobuki_message})
|
||||||
data = mqtt_client.subscribe("kobuki/data")
|
|
||||||
if data != 0:
|
|
||||||
return jsonify({data})
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
Reference in New Issue
Block a user