webclient finish, socket io finish, some changes in main
This commit is contained in:
@@ -17,11 +17,11 @@ MQTT_TOPIC_RETURN = b"coffee/return"
|
|||||||
SERVER_URL = "http://lires.de/unsecure/esp/online"
|
SERVER_URL = "http://lires.de/unsecure/esp/online"
|
||||||
|
|
||||||
# --- Eingänge ---
|
# --- Eingänge ---
|
||||||
an = Pin(5, Pin.IN)
|
an = Pin(5, Pin.IN, Pin.PULL_UP)
|
||||||
bereit = Pin(4, Pin.IN)
|
bereit = Pin(4, Pin.IN, Pin.PULL_UP)
|
||||||
fehler = Pin(14, Pin.IN)
|
fehler = Pin(14, Pin.IN, Pin.PULL_UP)
|
||||||
bohnen_voll = Pin(12, Pin.IN)
|
bohnen_voll = Pin(12, Pin.IN, Pin.PULL_UP)
|
||||||
Wasser_voll = Pin(13, Pin.IN)
|
wasser_voll = Pin(13, Pin.IN, Pin.PULL_UP)
|
||||||
|
|
||||||
# --- Ausgänge ---
|
# --- Ausgänge ---
|
||||||
toggle_machine = Pin(0, Pin.OUT)
|
toggle_machine = Pin(0, Pin.OUT)
|
||||||
@@ -96,7 +96,7 @@ while True:
|
|||||||
"bereit": bereit.value(),
|
"bereit": bereit.value(),
|
||||||
"fehler": fehler.value(),
|
"fehler": fehler.value(),
|
||||||
"bohnen_voll": bohnen_voll.value(),
|
"bohnen_voll": bohnen_voll.value(),
|
||||||
"Wasser_voll": Wasser_voll.value(),
|
"Wasser_voll": wasser_voll.value(),
|
||||||
"einschalten": toggle_machine.value(),
|
"einschalten": toggle_machine.value(),
|
||||||
"starten": starten.value(),
|
"starten": starten.value(),
|
||||||
|
|
||||||
@@ -164,5 +164,5 @@ while True:
|
|||||||
if bohnen_voll() == 1:
|
if bohnen_voll() == 1:
|
||||||
bohnen_voll(1)
|
bohnen_voll(1)
|
||||||
|
|
||||||
if Wasser_voll() == 1:
|
if wasser_voll() == 1:
|
||||||
Wasser_voll(1)
|
wasser_voll(1)
|
||||||
BIN
db/commands.db
BIN
db/commands.db
Binary file not shown.
@@ -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):
|
def refactor_and_use_esp_data(data):
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -4,6 +4,5 @@
|
|||||||
"ready": false,
|
"ready": false,
|
||||||
"peding_command": false,
|
"peding_command": false,
|
||||||
"berror": false,
|
"berror": false,
|
||||||
"error": "",
|
"error": ""
|
||||||
"lastConnectionProof": "2025-05-06 20:56:49.436343+00:00"
|
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ import os
|
|||||||
from modules.persistence import esp_conn_infos
|
from modules.persistence import esp_conn_infos
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from modules.socketio import resend_static_data
|
from modules.socketio import resend_static_data
|
||||||
|
from modules.persistence import load_dict, save_dict
|
||||||
|
|
||||||
esp = Blueprint('eps', __name__, url_prefix='/unsecure/esp')
|
esp = Blueprint('eps', __name__, url_prefix='/unsecure/esp')
|
||||||
|
|
||||||
@@ -43,6 +44,13 @@ def toggle_machine():
|
|||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
""", (fullCommand["command"], fullCommand["status"], fullCommand["command_id"]))
|
""", (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.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
client = mqtt.Client()
|
client = mqtt.Client()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ def index():
|
|||||||
beans = load_dict("beans")
|
beans = load_dict("beans")
|
||||||
machine = load_dict("machine")
|
machine = load_dict("machine")
|
||||||
coffee_count = get_coffee_count()
|
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)
|
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')
|
# @unsecure.route('/update')
|
||||||
@@ -51,8 +51,8 @@ def coffees_made():
|
|||||||
@unsecure.route('/water')
|
@unsecure.route('/water')
|
||||||
def water():
|
def water():
|
||||||
water = load_dict("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')
|
@unsecure.route('/beans')
|
||||||
def beans():
|
def beans():
|
||||||
beans = load_dict("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"])
|
||||||
|
|||||||
@@ -42,14 +42,14 @@ def on_message(client, userdata, msg):
|
|||||||
if msg.topic == MQTT_TOPIC_SUB:
|
if msg.topic == MQTT_TOPIC_SUB:
|
||||||
print(f"[MQTT] Nachricht empfangen: {msg.topic} -> {msg.payload.decode()}")
|
print(f"[MQTT] Nachricht empfangen: {msg.topic} -> {msg.payload.decode()}")
|
||||||
esp_conn_infos["last_seen"] = datetime.now()
|
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:
|
elif msg.topic == MQTT_TOPIC_RETURN:
|
||||||
print(f"[MQTT] Nachricht empfangen: {msg.topic} -> {msg.payload.decode()}")
|
print(f"[MQTT] Nachricht empfangen: {msg.topic} -> {msg.payload.decode()}")
|
||||||
try:
|
try:
|
||||||
payload = json.loads(msg.payload.decode())
|
payload = json.loads(msg.payload.decode())
|
||||||
command_id = payload.get("command_id")
|
command_id = payload.get("command_id")
|
||||||
if command_id:
|
if command_id:
|
||||||
update_command_status(command_id, "served") # form modules
|
update_command_status(command_id, "served") # form modules db
|
||||||
else:
|
else:
|
||||||
print("[MQTT] Keine command_id im Payload gefunden.")
|
print("[MQTT] Keine command_id im Payload gefunden.")
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
|
|||||||
@@ -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.
|
//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
|
//If later information is changed and should manipulate the html, it will come through socketio.js
|
||||||
|
stBut = gebId("machine-status-butt")
|
||||||
switch (machine.state) {
|
switch (machine.state) {
|
||||||
case "ON":
|
case "ON":
|
||||||
gebId("machine-status").innerText = "AN";
|
gebId("machine-status").innerText = "AN";
|
||||||
gebId("machine-status-butt").classList.remove("blink-orange");
|
stBut.classList.remove("blink-orange");
|
||||||
gebId("machine-status-butt").classList.remove("initBackRed");
|
stBut.classList.remove("initBackRed");
|
||||||
gebId("machine-status-butt").classList.add("initBackGreen");
|
stBut.classList.add("initBackGreen");
|
||||||
break;
|
break;
|
||||||
case "PENDING":
|
case "PENDING":
|
||||||
gebId("machine-status").innerText = "WARTEN";
|
gebId("machine-status").innerText = "WARTEN";
|
||||||
gebId("machine-status-butt").classList.add("blink-orange");
|
stBut.classList.add("blink-orange");
|
||||||
gebId("machine-status-butt").classList.remove("initBackRed");
|
stBut.classList.remove("initBackRed");
|
||||||
gebId("machine-status-butt").classList.remove("initBackGreen");
|
stBut.classList.remove("initBackGreen");
|
||||||
break;
|
break;
|
||||||
case "OFF":
|
case "OFF":
|
||||||
gebId("machine-status").innerText = "AUS";
|
gebId("machine-status").innerText = "AUS";
|
||||||
gebId("machine-status-butt").classList.remove("blink-orange");
|
stBut.classList.remove("blink-orange");
|
||||||
gebId("machine-status-butt").classList.add("initBackRed");
|
stBut.classList.add("initBackRed");
|
||||||
gebId("machine-status-butt").classList.remove("initBackGreen");
|
stBut.classList.remove("initBackGreen");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
gebId("machine-status").innerText = "UNBEKANNT";
|
gebId("machine-status").innerText = "UNBEKANNT";
|
||||||
gebId("machine-status-butt").classList.add("initBackRed");
|
stBut.classList.add("initBackRed");
|
||||||
}
|
}
|
||||||
// All there
|
// All there
|
||||||
function toggleMachine() {
|
function toggleMachine() {
|
||||||
@@ -87,9 +88,7 @@ function toggleMachine() {
|
|||||||
if (!result) {
|
if (!result) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("toggleMachine");
|
// console.log("toggleMachine");
|
||||||
document.getElementById("machine-status").innerText = "PENDING";
|
|
||||||
document.getElementById("machine-status-butt").classList.add("blink-orange");
|
|
||||||
fetch('/unsecure/esp/toggle-machine', { method: 'POST' })
|
fetch('/unsecure/esp/toggle-machine', { method: 'POST' })
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
|||||||
@@ -8,16 +8,23 @@
|
|||||||
<link rel="icon" href="{{ url_for('static', filename='gimmiCoffee_Logo.png') }}" type="image/png">
|
<link rel="icon" href="{{ url_for('static', filename='gimmiCoffee_Logo.png') }}" type="image/png">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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">
|
<div class="container">
|
||||||
<h1>Bohnenstatus</h1>
|
<h1>Bohnenstatus</h1>
|
||||||
|
|
||||||
<div class="status">
|
<div class="status">
|
||||||
<p><strong>Zuletzt gefüllt:</strong> {{ last_filled }}</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><!-- refactor the variable names-->
|
<p><strong>Aktueller Füllstand:</strong> {{ current_level }}%</p>
|
||||||
<p><strong>Kaffees seit letzter Füllung:</strong> {{ coffees_made }}</p><!-- refactor the variable names-->
|
<p><strong>Kaffees seit letzter Füllung:</strong> {{ coffees_made }}</p>
|
||||||
<p><strong>Gesamtanzahl der Füllungen:</strong> {{ total_refills }}</p><!-- refactor the variable names-->
|
<p><strong>Gesamtanzahl der Füllungen:</strong> {{ total_refills }}</p>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -9,8 +9,15 @@
|
|||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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>
|
<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>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -24,11 +31,11 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{ coffee.user }}</td>
|
<td>{{ coffee.user }}</td>
|
||||||
<td>{{ coffee.status }}</td>
|
<td>{{ coffee.status }}</td>
|
||||||
<td>{{ coffee.tstamp }}</td>
|
<td>{{ coffee.tstamp}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<script src="{{ url_for('static', filename='coffeesmade.js') }}"></script>
|
<!-- <script src="{{ url_for('static', filename='coffeesmade.js') }}"></script> -->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -8,16 +8,23 @@
|
|||||||
<link rel="icon" href="{{ url_for('static', filename='gimmiCoffee_Logo.png') }}" type="image/png">
|
<link rel="icon" href="{{ url_for('static', filename='gimmiCoffee_Logo.png') }}" type="image/png">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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">
|
<div class="container">
|
||||||
<h1>Wasserstatus</h1>
|
<h1>Wasserstatus</h1>
|
||||||
|
|
||||||
<div class="status">
|
<div class="status">
|
||||||
<p><strong>Zuletzt gefüllt:</strong> {{ last_filled }}</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><!-- refactor the variable names-->
|
<p><strong>Aktueller Füllstand:</strong> {{ current_level }}%</p>
|
||||||
<p><strong>Kaffees seit letzter Füllung:</strong> {{ coffees_made }}</p><!-- refactor the variable names-->
|
<p><strong>Kaffees seit letzter Füllung:</strong> {{ coffees_made }}</p>
|
||||||
<p><strong>Gesamtanzahl der Füllungen:</strong> {{ total_refills }}</p><!-- refactor the variable names-->
|
<p><strong>Gesamtanzahl der Füllungen:</strong> {{ total_refills }}</p>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user