mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
wrote some small comments
This commit is contained in:
@@ -3,9 +3,8 @@ import paho.mqtt.client as mqtt
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Create an MQTT client instance
|
||||
mqtt_client = mqtt.Client()
|
||||
|
||||
# Verbinding maken met de Raspberry Pi (broker)
|
||||
mqtt_client.username_pw_set("ishak", "kobuki")
|
||||
mqtt_client.connect("localhost", 1883, 60)
|
||||
mqtt_client.loop_start()
|
||||
@@ -16,12 +15,18 @@ def index():
|
||||
|
||||
@app.route('/move', methods=['POST'])
|
||||
def move():
|
||||
# Get the direction from the form data
|
||||
direction = request.form['direction']
|
||||
|
||||
# Publish the direction to the MQTT topic "home/commands"
|
||||
result = mqtt_client.publish("home/commands", direction)
|
||||
|
||||
# Check if the publish was successful
|
||||
if result.rc == mqtt.MQTT_ERR_SUCCESS:
|
||||
return jsonify({"message": "Bericht succesvol gepubliceerd"}), 200
|
||||
else:
|
||||
return jsonify({"message": "Fout bij het publiceren van bericht"}), 500
|
||||
|
||||
# Run the Flask application in debug mode
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
app.run(debug=True)
|
Reference in New Issue
Block a user