From f7d9c3e8c7eea4056dd54379ccac671d2f6f2ba6 Mon Sep 17 00:00:00 2001 From: derlole <122916573+derlole@users.noreply.github.com> Date: Mon, 12 May 2025 10:36:25 +0000 Subject: [PATCH] webclient finish, socket io finish, some changes in main --- aaaSonstiges/micropython/main.py | 26 +++++++++++++------------- db/commands.db | Bin 16384 -> 16384 bytes modules/other.py | 19 +++++++++++++++++++ persistence/machine.json | 3 +-- routes/esp_routes.py | 8 ++++++++ routes/unsecure_routes.py | 6 +++--- server.py | 4 ++-- static/script.js | 25 ++++++++++++------------- templates/beans.html | 17 ++++++++++++----- templates/coffees.html | 13 ++++++++++--- templates/water.html | 17 ++++++++++++----- 11 files changed, 92 insertions(+), 46 deletions(-) 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 68db1a3584577f4803b2abe9a882765c4026acfa..118b91ac5be208440ce147f30c93538745c7735c 100644 GIT binary patch delta 356 zcmZo@U~Fh$oFL68JWk4 z$xlzuNsZ4^ODQr|_3!XfZTm&}YM`B}K&?O^1P%u_1##D{dVM+^9N$elaoTVqjok<>kN2 z!2g>63I9+2PyBa*L2{a3nT?r=QS}`sh!Q=>0iyWJ*+G {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 @@ +
+
gimmiCoffee
+ +

Bohnenstatus

-

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 }}

- + \ No newline at end of file diff --git a/templates/coffees.html b/templates/coffees.html index 170db87..f1e235e 100644 --- a/templates/coffees.html +++ b/templates/coffees.html @@ -9,8 +9,15 @@ +
+
gimmiCoffee
+ +

Coffee History

- + @@ -24,11 +31,11 @@ - + {% endfor %}
{{ coffee.user }} {{ coffee.status }}{{ coffee.tstamp }}{{ coffee.tstamp}}
- + \ No newline at end of file diff --git a/templates/water.html b/templates/water.html index 852521f..90c7b54 100644 --- a/templates/water.html +++ b/templates/water.html @@ -8,16 +8,23 @@ +
+
gimmiCoffee
+ +

Wasserstatus

-

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 }}

- + \ No newline at end of file