This commit is contained in:
derlole
2025-05-09 11:21:53 +00:00
parent 416d30ae1c
commit 175c918c49
3 changed files with 39 additions and 16 deletions

View File

@@ -50,4 +50,25 @@ def toggle_machine():
client.publish(MQTT_TOPIC, json.dumps(fullCommand))
client.disconnect()
return jsonify({"status": json.dumps(fullCommand)})
@esp.route('/make_coffee', methods=['POST'])
def make_coffee():
randID = random.randint(1000, 9999)
fullCommand = {'command': 'make_coffee', 'status': 'pending', 'command_id': randID}
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
cursor.execute("""
INSERT INTO commands (command, status, command_id)
VALUES (?, ?, ?)
""", (fullCommand["command"], fullCommand["status"], fullCommand["command_id"]))
conn.commit()
conn.close()
client = mqtt.Client()
client.connect(MQTT_BROKER, MQTT_PORT, 60)
client.publish(MQTT_TOPIC, json.dumps(fullCommand))
client.disconnect()
return jsonify({"status": json.dumps(fullCommand)})