mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
test if i still get error
This commit is contained in:
@@ -50,21 +50,39 @@ def control():
|
|||||||
|
|
||||||
@app.route('/move', methods=['POST'])
|
@app.route('/move', methods=['POST'])
|
||||||
def move():
|
def move():
|
||||||
data = request.get_json()
|
try:
|
||||||
direction = data.get("direction")
|
# Haal de richting op van de request
|
||||||
|
data = request.get_json()
|
||||||
|
direction = data.get("direction")
|
||||||
|
|
||||||
db_connection = get_db()
|
if not direction:
|
||||||
cursor = db_connection.cursor()
|
return jsonify({"status": "error", "message": "Direction is required"}), 400
|
||||||
cursor.execute("INSERT INTO command (direction) VALUES (%s)", (direction,))
|
|
||||||
db_connection.commit()
|
|
||||||
cursor.close()
|
|
||||||
db_connection.close()
|
|
||||||
|
|
||||||
# Verstuur de richting via MQTT
|
# Maak verbinding met de database
|
||||||
if direction:
|
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})
|
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():
|
||||||
|
Reference in New Issue
Block a user