wrote some small comments

This commit is contained in:
ishak jmilou.ishak
2024-10-28 16:57:53 +01:00
parent edf1cabdf3
commit dd49de9d8c
3 changed files with 57 additions and 3 deletions

View File

@@ -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)