feat: implement command status update and enhance MQTT message handling

This commit is contained in:
derlole
2025-05-08 13:26:43 +00:00
parent c3d27b9e37
commit 20fa37b0d9
6 changed files with 54 additions and 14 deletions

View File

@@ -29,16 +29,12 @@ def esp_online():
esp_conn_infos["last_seen"] = datetime.now()
esp_conn_infos["connection_valid"] = True
resend_static_data()
print(f"ESP ONLINE von IP: {esp_ip}, roher IP: {sender_ip}")
return jsonify({"status": "ok"})
@esp.route('/toggle-machine', methods=['POST'])
def toggle_machine():
print("ESP: toggle-machine")
randID = random.randint(1000, 9999)
fullCommand = {'command': 'toggle_machine', 'status': 'pending', 'command_id': randID}
print("ESP: toggle-machine 1")
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
@@ -49,10 +45,9 @@ def toggle_machine():
conn.commit()
conn.close()
print("ESP: toggle-machine 2")
client = mqtt.Client()
client.connect(MQTT_BROKER, MQTT_PORT, 60)
client.publish(MQTT_TOPIC, json.dumps(fullCommand))
client.disconnect()
print("ESP: toggle-machine 3")
return jsonify({"status": json.dumps(fullCommand)})