diff --git a/aaaSonstiges/micropython/main.py b/aaaSonstiges/micropython/main.py index 76ab305..06c73c2 100644 --- a/aaaSonstiges/micropython/main.py +++ b/aaaSonstiges/micropython/main.py @@ -17,11 +17,11 @@ MQTT_TOPIC_RETURN = b"coffee/return" SERVER_URL = "http://lires.de/unsecure/esp/online" # --- Eingänge --- -an = Pin(5, Pin.IN) -bereit = Pin(4, Pin.IN) -fehler = Pin(14, Pin.IN) -bohnen_voll = Pin(12, Pin.IN) -Wasser_voll = Pin(13, Pin.IN) +an = Pin(5, Pin.IN, Pin.PULL_UP) +bereit = Pin(4, Pin.IN, Pin.PULL_UP) +fehler = Pin(14, Pin.IN, Pin.PULL_UP) +bohnen_voll = Pin(12, Pin.IN, Pin.PULL_UP) +wasser_voll = Pin(13, Pin.IN, Pin.PULL_UP) # --- Ausgänge --- toggle_machine = Pin(0, Pin.OUT) @@ -96,7 +96,7 @@ while True: "bereit": bereit.value(), "fehler": fehler.value(), "bohnen_voll": bohnen_voll.value(), - "Wasser_voll": Wasser_voll.value(), + "Wasser_voll": wasser_voll.value(), "einschalten": toggle_machine.value(), "starten": starten.value(), @@ -121,14 +121,14 @@ while True: time.sleep(5) client = None - # Einschalten der Kaffeemaschine + # Einschalten der Kaffeemaschine if kaffee_machen == 1: toggle_machine(1) time.sleep(1) toggle_machine(0) - # Starten der Kaffeemaschine + # Starten der Kaffeemaschine if kaffee_machen == 1 and an() == 1 and bereit() == 1 and fehler() == 0: starten(1) time.sleep(1) @@ -137,18 +137,18 @@ while True: else: starten(0) gestartet = 0 - #Vorbereitung der Kaffeemaschine + #Vorbereitung der Kaffeemaschine if bereit == 0 and an==1 and fehler==0 : vorbereitung=1 - # Vorbereitung der Kaffeemaschine + # Vorbereitung der Kaffeemaschine if bereit() == 0 and an() == 1 and fehler() == 0: vorbereitung = 1 - # Kaffeemaschine fertig + # Kaffeemaschine fertig if bereit() == 1 and an() == 1 and fehler() == 0 and gestartet == 1: kaffee_fertig=1 gestartet = 0 @@ -164,5 +164,5 @@ while True: if bohnen_voll() == 1: bohnen_voll(1) - if Wasser_voll() == 1: - Wasser_voll(1) \ No newline at end of file + if wasser_voll() == 1: + wasser_voll(1) \ No newline at end of file diff --git a/db/commands.db b/db/commands.db index 68db1a3..118b91a 100644 Binary files a/db/commands.db and b/db/commands.db differ diff --git a/modules/other.py b/modules/other.py index 796eb95..a5d6571 100644 --- a/modules/other.py +++ b/modules/other.py @@ -1,4 +1,23 @@ +# this function is processing the cyclic data from the esp format: +# [off_value/on_value] +# { +# # eingänge +# "an": [1/0], +# "bereit": [1/0], +# "fehler": [1/0], +# "bohnen_voll": [1/0], +# "Wasser_voll": [1/0], +# +# # ausgänge +# "einschalten": [0/1], +# "starten": [0/1], +# +# # status +# "kaffee_machen": [0/1], +# "vorbereitung": [0/1], +# "kaffee_fertig": [0/1], +# } def refactor_and_use_esp_data(data): return diff --git a/persistence/machine.json b/persistence/machine.json index 5747d0d..a17408b 100644 --- a/persistence/machine.json +++ b/persistence/machine.json @@ -4,6 +4,5 @@ "ready": false, "peding_command": false, "berror": false, - "error": "", - "lastConnectionProof": "2025-05-06 20:56:49.436343+00:00" + "error": "" } \ No newline at end of file diff --git a/routes/esp_routes.py b/routes/esp_routes.py index 70e4d77..9c7dbc3 100644 --- a/routes/esp_routes.py +++ b/routes/esp_routes.py @@ -8,6 +8,7 @@ import os from modules.persistence import esp_conn_infos from datetime import datetime, timedelta from modules.socketio import resend_static_data +from modules.persistence import load_dict, save_dict esp = Blueprint('eps', __name__, url_prefix='/unsecure/esp') @@ -43,6 +44,13 @@ def toggle_machine(): VALUES (?, ?, ?) """, (fullCommand["command"], fullCommand["status"], fullCommand["command_id"])) + + new_status = load_dict("machine") + new_status["state"] = "PENDING" + save_dict("machine", new_status) + + resend_static_data() + conn.commit() conn.close() client = mqtt.Client() diff --git a/routes/unsecure_routes.py b/routes/unsecure_routes.py index 31de82b..69eaf5c 100644 --- a/routes/unsecure_routes.py +++ b/routes/unsecure_routes.py @@ -13,7 +13,7 @@ def index(): beans = load_dict("beans") machine = load_dict("machine") coffee_count = get_coffee_count() - print(f"Water: {water}, Beans: {beans}, Machine: {machine}") + # print(f"[DEBUG] Water: {water}, Beans: {beans}, Machine: {machine}") return render_template('index.html', title='gimmiCoffee', water=water, beans=beans, machine=machine, esp_conn_infos=esp_conn_infos, coffee_count=coffee_count) # @unsecure.route('/update') @@ -51,8 +51,8 @@ def coffees_made(): @unsecure.route('/water') def water(): water = load_dict("water") - return render_template('water.html', title='gimmiCoffee', last_filled=water["lastFilled"], current_level=water["fill"], total_refills=water["refilled"], coffees_made=water["coffeesOnFill"]) + return render_template('water.html', title='gimmiCoffee', last_filled=datetime.strptime(water["lastFilled"], "%Y-%m-%d %H:%M:%S.%f"), current_level=water["fill"], total_refills=water["refilled"], coffees_made=water["coffeesOnFill"]) @unsecure.route('/beans') def beans(): beans = load_dict("beans") - return render_template('beans.html', title='gimmiCoffee', last_filled=beans["lastFilled"], current_level=beans["fill"], total_refills=beans["refilled"], coffees_made=beans["coffeesOnFill"]) + return render_template('beans.html', title='gimmiCoffee', last_filled=datetime.strptime(beans["lastFilled"], "%Y-%m-%d %H:%M:%S.%f"), current_level=beans["fill"], total_refills=beans["refilled"], coffees_made=beans["coffeesOnFill"]) diff --git a/server.py b/server.py index 977df4a..cb6e80a 100644 --- a/server.py +++ b/server.py @@ -42,14 +42,14 @@ def on_message(client, userdata, msg): if msg.topic == MQTT_TOPIC_SUB: print(f"[MQTT] Nachricht empfangen: {msg.topic} -> {msg.payload.decode()}") esp_conn_infos["last_seen"] = datetime.now() - refactor_and_use_esp_data(msg.payload.decode()) + refactor_and_use_esp_data(msg.payload.decode()) # form modules other elif msg.topic == MQTT_TOPIC_RETURN: print(f"[MQTT] Nachricht empfangen: {msg.topic} -> {msg.payload.decode()}") try: payload = json.loads(msg.payload.decode()) command_id = payload.get("command_id") if command_id: - update_command_status(command_id, "served") # form modules + update_command_status(command_id, "served") # form modules db else: print("[MQTT] Keine command_id im Payload gefunden.") except json.JSONDecodeError as e: diff --git a/static/script.js b/static/script.js index 6762a60..2b0d9b9 100644 --- a/static/script.js +++ b/static/script.js @@ -53,29 +53,30 @@ if (beans.fill < 20) { } //all there given if generated html manipulations are not else-ed because the else condition is always in the dafult. //If later information is changed and should manipulate the html, it will come through socketio.js +stBut = gebId("machine-status-butt") switch (machine.state) { case "ON": gebId("machine-status").innerText = "AN"; - gebId("machine-status-butt").classList.remove("blink-orange"); - gebId("machine-status-butt").classList.remove("initBackRed"); - gebId("machine-status-butt").classList.add("initBackGreen"); + stBut.classList.remove("blink-orange"); + stBut.classList.remove("initBackRed"); + stBut.classList.add("initBackGreen"); break; case "PENDING": gebId("machine-status").innerText = "WARTEN"; - gebId("machine-status-butt").classList.add("blink-orange"); - gebId("machine-status-butt").classList.remove("initBackRed"); - gebId("machine-status-butt").classList.remove("initBackGreen"); + stBut.classList.add("blink-orange"); + stBut.classList.remove("initBackRed"); + stBut.classList.remove("initBackGreen"); break; case "OFF": gebId("machine-status").innerText = "AUS"; - gebId("machine-status-butt").classList.remove("blink-orange"); - gebId("machine-status-butt").classList.add("initBackRed"); - gebId("machine-status-butt").classList.remove("initBackGreen"); + stBut.classList.remove("blink-orange"); + stBut.classList.add("initBackRed"); + stBut.classList.remove("initBackGreen"); break; default: gebId("machine-status").innerText = "UNBEKANNT"; - gebId("machine-status-butt").classList.add("initBackRed"); + stBut.classList.add("initBackRed"); } // All there function toggleMachine() { @@ -87,9 +88,7 @@ function toggleMachine() { if (!result) { return; } - console.log("toggleMachine"); - document.getElementById("machine-status").innerText = "PENDING"; - document.getElementById("machine-status-butt").classList.add("blink-orange"); + // console.log("toggleMachine"); fetch('/unsecure/esp/toggle-machine', { method: 'POST' }) .then(res => res.json()) .then(data => { diff --git a/templates/beans.html b/templates/beans.html index bc99900..f9d8f3c 100644 --- a/templates/beans.html +++ b/templates/beans.html @@ -8,16 +8,23 @@
+Zuletzt gefüllt: {{ last_filled }}
-Aktueller Füllstand: {{ current_level }}%
-Kaffees seit letzter Füllung: {{ coffees_made }}
-Gesamtanzahl der Füllungen: {{ total_refills }}
+Zuletzt gefüllt: {{ last_filled.strftime('%d-%m-%Y %H:%M:%S') }}
+Aktueller Füllstand: {{ current_level }}%
+Kaffees seit letzter Füllung: {{ coffees_made }}
+Gesamtanzahl der Füllungen: {{ total_refills }}