This commit is contained in:
derlole
2025-05-06 15:38:55 +00:00
parent 0d7e6e7925
commit 29e119560d

View File

@@ -32,9 +32,10 @@ def esp_online():
@esp.route('/toggle-machine', methods=['GET']) @esp.route('/toggle-machine', methods=['GET'])
def toggle_machine(): def toggle_machine():
print("ESP: toggle-machine")
randID = random.randint(1000, 9999) randID = random.randint(1000, 9999)
fullCommand = {'command': 'toggle_machine', 'status': 'pending', 'command_id': randID} fullCommand = {'command': 'toggle_machine', 'status': 'pending', 'command_id': randID}
print("ESP: toggle-machine 1")
conn = sqlite3.connect(DB_PATH) conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor() cursor = conn.cursor()
@@ -45,10 +46,10 @@ def toggle_machine():
conn.commit() conn.commit()
conn.close() conn.close()
print("ESP: toggle-machine 2")
client = mqtt.Client() client = mqtt.Client()
client.connect(MQTT_BROKER, MQTT_PORT, 60) client.connect(MQTT_BROKER, MQTT_PORT, 60)
client.publish(MQTT_TOPIC, json.dumps(fullCommand)) client.publish(MQTT_TOPIC, json.dumps(fullCommand))
client.disconnect() client.disconnect()
print("ESP: toggle-machine 3")
return jsonify({"status": json.dumps(fullCommand)}) return jsonify({"status": json.dumps(fullCommand)})