test if i still get error

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

View File

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