changed order

This commit is contained in:
ishak jmilou.ishak
2024-12-17 14:58:31 +01:00
parent 4307d0a8d5
commit c4d2888fbf

View File

@@ -50,39 +50,21 @@ def control():
@app.route('/move', methods=['POST']) @app.route('/move', methods=['POST'])
def move(): def move():
try: data = request.get_json()
# Haal de richting op van de request direction = data.get("direction")
data = request.get_json()
direction = data.get("direction")
if not direction: # Verstuur de richting via MQTT
return jsonify({"status": "error", "message": "Direction is required"}), 400 if direction:
# Maak verbinding met de database
conn = get_db()
cursor = conn.cursor()
# Sla de richting op in de database
cursor.execute("INSERT INTO command (direction) VALUES (%s)", (direction,))
conn.commit()
# Sluit de cursor en de verbinding
cursor.close()
conn.close()
# Verstuur de richting via MQTT
mqtt_client.publish("home/commands", direction) mqtt_client.publish("home/commands", direction)
return jsonify({"status": "success", "direction": direction}) db_connection = get_db()
cursor = db_connection.cursor()
except mysql.connector.Error as e: cursor.execute("INSERT INTO command (direction) VALUES (%s)", (direction,))
# Foutafhandeling voor databasefouten db_connection.commit()
return jsonify({"status": "error", "message": str(e)}), 500 cursor.close()
db_connection.close()
except Exception as e:
# Algemene foutafhandeling return jsonify({"status": "success", "direction": direction})
return jsonify({"status": "error", "message": "An error occurred", "details": str(e)}), 500
@app.route('/data', methods=['GET']) @app.route('/data', methods=['GET'])
def data(): def data():