update navigation links, enhance NFC data display, and improve MQTT connection handling

This commit is contained in:
Manuel Weiser 2025-02-13 12:59:43 +01:00
parent be0a23e736
commit d46d5e14d2
6 changed files with 38 additions and 22 deletions

View File

@ -20,7 +20,7 @@
<a href="/">Start</a> <a href="/">Start</a>
<a href="/waage">Scale</a> <a href="/waage">Scale</a>
<a href="/spoolman">Spoolman/Bambu</a> <a href="/spoolman">Spoolman/Bambu</a>
<a href="/rfid">RFID</a> <a href="/">About</a>
</nav> </nav>
<div class="status-container"> <div class="status-container">
<div class="status-item"> <div class="status-item">

View File

@ -448,7 +448,7 @@ function updateNfcData(data) {
// HTML für die Datenanzeige erstellen // HTML für die Datenanzeige erstellen
let html = ` let html = `
<div style="margin-top: 10px;"> <div class="nfc-card-data" style="margin-top: 10px;">
<p><strong>Brand:</strong> ${data.brand || 'N/A'}</p> <p><strong>Brand:</strong> ${data.brand || 'N/A'}</p>
<p><strong>Type:</strong> ${data.type || 'N/A'} ${data.color_hex ? `<span style=" <p><strong>Type:</strong> ${data.type || 'N/A'} ${data.color_hex ? `<span style="
background-color: #${data.color_hex}; background-color: #${data.color_hex};

View File

@ -255,7 +255,7 @@ button:hover {
p { p {
font-size: 1rem; font-size: 1rem;
color: #555; color: #ffffff;
} }
a { a {
@ -325,6 +325,13 @@ a:hover {
margin-top: 10px; margin-top: 10px;
} }
.nfc-card-data {
padding-left: 20px !important;
color: white !important;
font-weight: bold !important;
margin: 0 auto !important;
}
.nfc-success { .nfc-success {
color: green; color: green;
} }

View File

@ -422,9 +422,6 @@ void reconnect() {
} }
void mqtt_loop(void * parameter) { void mqtt_loop(void * parameter) {
oledShowMessage("Bambu Connected");
bambu_connected = true;
oledShowTopRow();
for(;;) { for(;;) {
if (pauseBambuMqttTask) { if (pauseBambuMqttTask) {
vTaskDelay(10000); vTaskDelay(10000);
@ -452,13 +449,16 @@ bool setupMqtt() {
return false; return false;
} }
if (success && bambu_ip != "" && bambu_accesscode != "" && bambu_serialnr != "") { if (success && bambu_ip != "" && bambu_accesscode != "" && bambu_serialnr != "")
{
sslClient.setCACert(root_ca); sslClient.setCACert(root_ca);
sslClient.setInsecure(); sslClient.setInsecure();
client.setServer(bambu_ip, 8883); client.setServer(bambu_ip, 8883);
// Verbinden mit dem MQTT-Server // Verbinden mit dem MQTT-Server
if (client.connect(bambu_serialnr, bambu_username, bambu_accesscode)) { bool connected = true;
if (client.connect(bambu_serialnr, bambu_username, bambu_accesscode))
{
client.setCallback(mqtt_callback); client.setCallback(mqtt_callback);
client.setBufferSize(5120); client.setBufferSize(5120);
// Optional: Topic abonnieren // Optional: Topic abonnieren
@ -467,6 +467,17 @@ bool setupMqtt() {
Serial.println("MQTT-Client initialisiert"); Serial.println("MQTT-Client initialisiert");
oledShowTopRow(); oledShowTopRow();
oledShowMessage("Bambu Connected");
bambu_connected = true;
}
else
{
Serial.println("Fehler: Konnte sich nicht beim MQTT-Server anmelden");
oledShowMessage("Bambu Connection Failed");
oledShowTopRow();
vTaskDelay(2000 / portTICK_PERIOD_MS);
connected = false;
}
xTaskCreatePinnedToCore( xTaskCreatePinnedToCore(
mqtt_loop, /* Function to implement the task */ mqtt_loop, /* Function to implement the task */
@ -477,14 +488,10 @@ bool setupMqtt() {
&BambuMqttTask, /* Task handle. */ &BambuMqttTask, /* Task handle. */
mqttTaskCore); /* Core where the task should run */ mqttTaskCore); /* Core where the task should run */
} else { if (!connected) return false;
Serial.println("Fehler: Konnte sich nicht beim MQTT-Server anmelden");
oledShowMessage("Bambu Connection Failed");
oledShowTopRow();
vTaskDelay(2000 / portTICK_PERIOD_MS);
return false;
} }
} else { else
{
Serial.println("Fehler: Keine MQTT-Daten vorhanden"); Serial.println("Fehler: Keine MQTT-Daten vorhanden");
oledShowMessage("Bambu Credentials Missing"); oledShowMessage("Bambu Credentials Missing");
oledShowTopRow(); oledShowTopRow();

View File

@ -379,6 +379,8 @@ void scanRfidTask(void * parameter) {
// Wenn geschrieben wird Schleife aussetzen // Wenn geschrieben wird Schleife aussetzen
if (hasReadRfidTag != 3) if (hasReadRfidTag != 3)
{ {
yield();
uint8_t success; uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; uint8_t uidLength;

View File

@ -25,7 +25,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
sendAmsData(client); sendAmsData(client);
sendNfcData(client); sendNfcData(client);
foundNfcTag(client, hasReadRfidTag); foundNfcTag(client, hasReadRfidTag);
sendWriteResult(client, 0); sendWriteResult(client, 3);
} else if (type == WS_EVT_DISCONNECT) { } else if (type == WS_EVT_DISCONNECT) {
Serial.println("Client getrennt."); Serial.println("Client getrennt.");
} else if (type == WS_EVT_DATA) { } else if (type == WS_EVT_DATA) {