webclient finish, socket io finish, some changes in main

This commit is contained in:
derlole
2025-05-12 10:36:25 +00:00
parent 41b276c734
commit f7d9c3e8c7
11 changed files with 92 additions and 46 deletions

View File

@@ -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(),
@@ -164,5 +164,5 @@ while True:
if bohnen_voll() == 1:
bohnen_voll(1)
if Wasser_voll() == 1:
Wasser_voll(1)
if wasser_voll() == 1:
wasser_voll(1)

Binary file not shown.

View File

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

View File

@@ -4,6 +4,5 @@
"ready": false,
"peding_command": false,
"berror": false,
"error": "",
"lastConnectionProof": "2025-05-06 20:56:49.436343+00:00"
"error": ""
}

View File

@@ -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()

View File

@@ -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"])

View File

@@ -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:

View File

@@ -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 => {

View File

@@ -8,16 +8,23 @@
<link rel="icon" href="{{ url_for('static', filename='gimmiCoffee_Logo.png') }}" type="image/png">
</head>
<body>
<header>
<div class="site-title" onclick="window.location.href = '/unsecure'">gimmiCoffee</div>
<div class="user-actions">
<span class="username">Max Mustermann</span>
<a href="/logout" class="logout">Logout</a>
</div>
</header>
<div class="container">
<h1>Bohnenstatus</h1>
<div class="status">
<p><strong>Zuletzt gefüllt:</strong> {{ last_filled }}</p><!-- refactor the variable names-->
<p><strong>Aktueller Füllstand:</strong> {{ current_level }}%</p><!-- refactor the variable names-->
<p><strong>Kaffees seit letzter Füllung:</strong> {{ coffees_made }}</p><!-- refactor the variable names-->
<p><strong>Gesamtanzahl der Füllungen:</strong> {{ total_refills }}</p><!-- refactor the variable names-->
<p><strong>Zuletzt gefüllt:</strong> {{ last_filled.strftime('%d-%m-%Y %H:%M:%S') }}</p>
<p><strong>Aktueller Füllstand:</strong> {{ current_level }}%</p>
<p><strong>Kaffees seit letzter Füllung:</strong> {{ coffees_made }}</p>
<p><strong>Gesamtanzahl der Füllungen:</strong> {{ total_refills }}</p>
</div>
</div>
<button class="homeBut" onclick="window.location.href = '/unsecure'">Get Me Home</button>
<!-- <button class="homeBut" onclick="window.location.href = '/unsecure'">Get Me Home</button> -->
</body>
</html>

View File

@@ -9,8 +9,15 @@
</head>
<body>
<header>
<div class="site-title" onclick="window.location.href = '/unsecure'">gimmiCoffee</div>
<div class="user-actions">
<span class="username">Max Mustermann</span>
<a href="/logout" class="logout">Logout</a>
</div>
</header>
<h1>Coffee History</h1>
<button class="homeBut" onclick="window.location.href = '/unsecure'">get me home</button>
<!-- <button class="homeBut" onclick="window.location.href = '/unsecure'">get me home</button> --> <!-- the redirection is available over the gimmiCoffee writing-->
<table>
<thead>
<tr>
@@ -29,6 +36,6 @@
{% endfor %}
</tbody>
</table>
<script src="{{ url_for('static', filename='coffeesmade.js') }}"></script>
<!-- <script src="{{ url_for('static', filename='coffeesmade.js') }}"></script> -->
</body>
</html>

View File

@@ -8,16 +8,23 @@
<link rel="icon" href="{{ url_for('static', filename='gimmiCoffee_Logo.png') }}" type="image/png">
</head>
<body>
<header>
<div class="site-title" onclick="window.location.href = '/unsecure'">gimmiCoffee</div>
<div class="user-actions">
<span class="username">Max Mustermann</span>
<a href="/logout" class="logout">Logout</a>
</div>
</header>
<div class="container">
<h1>Wasserstatus</h1>
<div class="status">
<p><strong>Zuletzt gefüllt:</strong> {{ last_filled }}</p><!-- refactor the variable names-->
<p><strong>Aktueller Füllstand:</strong> {{ current_level }}%</p><!-- refactor the variable names-->
<p><strong>Kaffees seit letzter Füllung:</strong> {{ coffees_made }}</p><!-- refactor the variable names-->
<p><strong>Gesamtanzahl der Füllungen:</strong> {{ total_refills }}</p><!-- refactor the variable names-->
<p><strong>Zuletzt gefüllt:</strong> {{ last_filled.strftime('%d-%m-%Y %H:%M:%S') }}</p>
<p><strong>Aktueller Füllstand:</strong> {{ current_level }}%</p>
<p><strong>Kaffees seit letzter Füllung:</strong> {{ coffees_made }}</p>
<p><strong>Gesamtanzahl der Füllungen:</strong> {{ total_refills }}</p>
</div>
</div>
<button class="homeBut" onclick="window.location.href = '/unsecure'">Get Me Home</button>
<!-- <button class="homeBut" onclick="window.location.href = '/unsecure'">Get Me Home</button> -->
</body>
</html>