diff --git a/html/rfid.html b/html/rfid.html index b3b2527..a481c04 100644 --- a/html/rfid.html +++ b/html/rfid.html @@ -141,15 +141,6 @@ - -
-
-

Bambu AMS

-
-
Wait for AMS-Data...
-
-
-
diff --git a/html/rfid.js b/html/rfid.js index 34680e6..826adc2 100644 --- a/html/rfid.js +++ b/html/rfid.js @@ -11,7 +11,7 @@ let reconnectTimer = null; // WebSocket Funktionen function startHeartbeat() { if (heartbeatTimer) clearInterval(heartbeatTimer); - + heartbeatTimer = setInterval(() => { // Prüfe ob zu lange keine Antwort kam if (Date.now() - lastHeartbeatResponse > HEARTBEAT_TIMEOUT) { @@ -29,7 +29,7 @@ function startHeartbeat() { updateConnectionStatus(); return; } - + try { // Sende Heartbeat socket.send(JSON.stringify({ type: 'heartbeat' })); @@ -83,7 +83,7 @@ function initWebSocket() { isConnected = false; updateConnectionStatus(); if (heartbeatTimer) clearInterval(heartbeatTimer); - + // Bei Fehler Verbindung schließen und neu aufbauen if (socket) { socket.close(); @@ -109,7 +109,7 @@ function initWebSocket() { const bambuDot = document.getElementById('bambuDot'); const spoolmanDot = document.getElementById('spoolmanDot'); const ramStatus = document.getElementById('ramStatus'); - + if (bambuDot) { bambuDot.className = 'status-dot ' + (data.bambu_connected ? 'online' : 'offline'); // Add click handler only when offline @@ -208,7 +208,7 @@ document.addEventListener('spoolmanError', function(event) { showNotification(`Spoolman Error: ${event.detail.message}`, false); }); -document.addEventListener('filamentSelected', function(event) { +document.addEventListener('filamentSelected', function (event) { updateNfcInfo(); // Zeige Spool-Buttons wenn ein Filament ausgewählt wurde const selectedText = document.getElementById("selected-filament").textContent; @@ -686,4 +686,4 @@ function showNotification(message, isSuccess) { notification.remove(); }, 300); }, 3000); -} +} \ No newline at end of file diff --git a/html/rfid_bambu.html b/html/rfid_bambu.html new file mode 100644 index 0000000..b3b2527 --- /dev/null +++ b/html/rfid_bambu.html @@ -0,0 +1,160 @@ + + + + + + FilaMan - Filament Management Tool + + + + + + + + + + +
+
+ +
+
+
+

Statistics

+ +
+
+

Spools

+
+ total: + +
+ without Tag: + +
+
+ +
+
+

Overview

+
    +
  • + Manufacturer: + +
  • +
  • + Weight: + +
  • +
  • + Length: + +
  • +
+
+
+

Materials

+
    + +
+
+
+
+
+
+

NFC-Tag

+ +
+
+
+
+ + +
+
+

Spoolman Spools

+ +
+ + +
+
+ + +
+ + +
+
+

Bambu AMS

+
+
Wait for AMS-Data...
+
+
+
+
+
+ + + + + + diff --git a/html/spoolman.html b/html/spoolman.html index 1b615f7..16736e0 100644 --- a/html/spoolman.html +++ b/html/spoolman.html @@ -57,6 +57,31 @@ toggleOctoFields(); }; + function removeBambuCredentials() { + fetch('/api/bambu?remove=true') + .then(response => response.json()) + .then(data => { + if (data.success) { + document.getElementById('bambuIp').value = ''; + document.getElementById('bambuSerial').value = ''; + document.getElementById('bambuCode').value = ''; + document.getElementById('autoSend').checked = false; + document.getElementById('autoSendTime').value = ''; + document.getElementById('bambuStatusMessage').innerText = 'Bambu Credentials removed!'; + // Reload with forced cache refresh after short delay + setTimeout(() => { + window.location.replace('/'); + location.reload(true); + }, 1500); + } else { + document.getElementById('bambuStatusMessage').innerText = 'Error while removing Bambu Credentials.'; + } + }) + .catch(error => { + document.getElementById('bambuStatusMessage').innerText = 'Error while removing: ' + error.message; + }); + } + function checkSpoolmanInstance() { const url = document.getElementById('spoolmanUrl').value; const spoolmanOctoEnabled = document.getElementById('spoolmanOctoEnabled').checked; @@ -89,6 +114,11 @@ .then(data => { if (data.healthy) { document.getElementById('bambuStatusMessage').innerText = 'Bambu Credentials saved!'; + // Reload with forced cache refresh after short delay + setTimeout(() => { + window.location.replace('/'); + location.reload(true); + }, 1500); } else { document.getElementById('bambuStatusMessage').innerText = 'Error while saving Bambu Credentials.'; } @@ -162,6 +192,7 @@ +

diff --git a/src/bambu.cpp b/src/bambu.cpp index f5f3752..818f92d 100644 --- a/src/bambu.cpp +++ b/src/bambu.cpp @@ -27,6 +27,7 @@ const char* bambu_serialnr = nullptr; String g_bambu_ip = ""; String g_bambu_accesscode = ""; String g_bambu_serialnr = ""; +bool bambuDisabled = false; bool bambu_connected = false; bool autoSendToBambu = false; @@ -37,6 +38,32 @@ int ams_count = 0; String amsJsonData; // Speichert das fertige JSON für WebSocket-Clients AMSData ams_data[MAX_AMS]; // Definition des Arrays; +bool removeBambuCredentials() { + if (BambuMqttTask) { + vTaskDelete(BambuMqttTask); + } + + if (!removeJsonValue("/bambu_credentials.json")) { + Serial.println("Fehler beim Löschen der Bambu-Credentials."); + return false; + } + // Löschen der globalen Variablen + g_bambu_ip = ""; + g_bambu_accesscode = ""; + g_bambu_serialnr = ""; + bambu_ip = nullptr; + bambu_accesscode = nullptr; + bambu_serialnr = nullptr; + autoSendToBambu = false; + autoSetToBambuSpoolId = 0; + ams_count = 0; + amsJsonData = ""; + + bambuDisabled = true; + + return true; +} + bool saveBambuCredentials(const String& ip, const String& serialnr, const String& accesscode, bool autoSend, const String& autoSendTime) { if (BambuMqttTask) { vTaskDelete(BambuMqttTask); @@ -606,14 +633,13 @@ bool setupMqtt() { bool success = loadBambuCredentials(); if (!success) { - Serial.println("Failed to load Bambu credentials"); - oledShowMessage("Bambu Credentials Missing"); - vTaskDelay(2000 / portTICK_PERIOD_MS); + bambuDisabled = true; return false; } if (success && bambu_ip != "" && bambu_accesscode != "" && bambu_serialnr != "") { + bambuDisabled = false; sslClient.setCACert(root_ca); sslClient.setInsecure(); client.setServer(bambu_ip, 8883); @@ -654,10 +680,7 @@ bool setupMqtt() { } else { - Serial.println("Fehler: Keine MQTT-Daten vorhanden"); - oledShowMessage("Bambu Credentials Missing"); - oledShowTopRow(); - vTaskDelay(2000 / portTICK_PERIOD_MS); + bambuDisabled = true; return false; } return true; diff --git a/src/bambu.h b/src/bambu.h index 1dc7b3d..aef6c3b 100644 --- a/src/bambu.h +++ b/src/bambu.h @@ -30,7 +30,9 @@ extern int ams_count; extern AMSData ams_data[MAX_AMS]; extern bool autoSendToBambu; extern int autoSetToBambuSpoolId; +extern bool bambuDisabled; +bool removeBambuCredentials(); bool loadBambuCredentials(); bool saveBambuCredentials(const String& bambu_ip, const String& bambu_serialnr, const String& bambu_accesscode, const bool autoSend, const String& autoSendTime); bool setupMqtt(); diff --git a/src/commonFS.cpp b/src/commonFS.cpp index 7940b22..b58f68d 100644 --- a/src/commonFS.cpp +++ b/src/commonFS.cpp @@ -1,6 +1,20 @@ #include "commonFS.h" #include +bool removeJsonValue(const char* filename) { + File file = LittleFS.open(filename, "r"); + if (!file) { + return true; + } + file.close(); + if (!LittleFS.remove(filename)) { + Serial.print("Fehler beim Löschen der Datei: "); + Serial.println(filename); + return false; + } + return true; +} + bool saveJsonValue(const char* filename, const JsonDocument& doc) { File file = LittleFS.open(filename, "w"); if (!file) { diff --git a/src/commonFS.h b/src/commonFS.h index d46b1e5..6cc2725 100644 --- a/src/commonFS.h +++ b/src/commonFS.h @@ -5,6 +5,7 @@ #include #include +bool removeJsonValue(const char* filename); bool saveJsonValue(const char* filename, const JsonDocument& doc); bool loadJsonValue(const char* filename, JsonDocument& doc); void initializeFileSystem(); diff --git a/src/main.cpp b/src/main.cpp index d9ead63..0b2c635 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,7 +100,7 @@ void loop() { // Wenn Bambu auto set Spool aktiv if (autoSendToBambu && autoSetToBambuSpoolId > 0) { - if (!bambu_connected) + if (!bambuDisabled && !bambu_connected) { bambu_restart(); } diff --git a/src/website.cpp b/src/website.cpp index 2e01604..18ac882 100644 --- a/src/website.cpp +++ b/src/website.cpp @@ -29,7 +29,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp if (type == WS_EVT_CONNECT) { Serial.println("Neuer Client verbunden!"); // Sende die AMS-Daten an den neuen Client - sendAmsData(client); + if (!bambuDisabled) sendAmsData(client); sendNfcData(client); foundNfcTag(client, 0); sendWriteResult(client, 3); @@ -213,7 +213,10 @@ void setupWebserver(AsyncWebServer &server) { // Route für RFID server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ Serial.println("Anfrage für /rfid erhalten"); - AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/rfid.html.gz", "text/html"); + + String page = (bambuDisabled) ? "/rfid.html.gz" : "/rfid_bambu.html.gz"; + AsyncWebServerResponse *response = request->beginResponse(LittleFS, page, "text/html"); + response->addHeader("Content-Encoding", "gzip"); response->addHeader("Cache-Control", CACHE_CONTROL); request->send(response); @@ -310,6 +313,15 @@ void setupWebserver(AsyncWebServer &server) { // Route für das Überprüfen der Bambu-Instanz server.on("/api/bambu", HTTP_GET, [](AsyncWebServerRequest *request){ + if (request->hasParam("remove")) { + if (removeBambuCredentials()) { + request->send(200, "application/json", "{\"success\": true}"); + } else { + request->send(500, "application/json", "{\"success\": false, \"error\": \"Fehler beim Löschen der Bambu-Credentials\"}"); + } + return; + } + if (!request->hasParam("bambu_ip") || !request->hasParam("bambu_serialnr") || !request->hasParam("bambu_accesscode")) { request->send(400, "application/json", "{\"success\": false, \"error\": \"Missing parameter\"}"); return;