diff --git a/html/header.html b/html/header.html index 53eb785..224a246 100644 --- a/html/header.html +++ b/html/header.html @@ -30,8 +30,7 @@
diff --git a/html/rfid.html b/html/rfid.html deleted file mode 100644 index 89358e7..0000000 --- a/html/rfid.html +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - FilaMan - Status - - - - - - - -
-

Device Status

- -
-
-
-

Weight

-
0g
-
-
-
-
-

NFC Tag

-
-

No tag detected

-
-
-
-
-
- - - - diff --git a/html/rfid.js b/html/rfid.js deleted file mode 100644 index 12597ac..0000000 --- a/html/rfid.js +++ /dev/null @@ -1,80 +0,0 @@ -let socket; -let isConnected = false; -const RECONNECT_INTERVAL = 5000; - -function initWebSocket() { - if (socket) { - socket.close(); - socket = null; - } - - try { - socket = new WebSocket('ws://' + window.location.host + '/ws'); - - socket.onopen = function() { - isConnected = true; - console.log("WebSocket connected"); - }; - - socket.onclose = function() { - isConnected = false; - setTimeout(initWebSocket, RECONNECT_INTERVAL); - }; - - socket.onmessage = function(event) { - const data = JSON.parse(event.data); - if (data.type === 'nfcData') { - updateNfcDisplay(data.payload); - } else if (data.type === 'heartbeat') { - updateStatusDots(data); - } else if (data.type === 'weight') { - document.getElementById('weightDisplay').textContent = data.value + 'g'; - } - }; - } catch (error) { - isConnected = false; - setTimeout(initWebSocket, RECONNECT_INTERVAL); - } -} - -function updateStatusDots(data) { - const filamanDot = document.getElementById('filamanDot'); - const ramStatus = document.getElementById('ramStatus'); - - if (filamanDot) { - filamanDot.style.backgroundColor = data.filaman_connected ? '#4caf50' : '#f44336'; - } - if (ramStatus) { - ramStatus.textContent = `${data.freeHeap}k free`; - } -} - -function updateNfcDisplay(data) { - const nfcInfo = document.getElementById('nfcInfo'); - if (data.error || data.info || !data || Object.keys(data).length === 0) { - nfcInfo.textContent = data.info || data.error || "No tag detected"; - return; - } - - let html = "Tag detected:
"; - if (data.sm_id) { - html += `Spool ID: ${data.sm_id}
`; - if (data.brand) html += `Brand: ${data.brand}
`; - if (data.type) html += `Material: ${data.type}
`; - } else if (data.location_id) { - html += `Location ID: ${data.location_id}
`; - } else { - html += "Unknown Tag Format"; - } - nfcInfo.innerHTML = html; -} - -document.addEventListener("DOMContentLoaded", function() { - initWebSocket(); - // Heartbeat loop - setInterval(() => { - if (socket && socket.readyState === WebSocket.OPEN) { - socket.send(JSON.stringify({ type: 'heartbeat' })); - } - }, 5000); -}); diff --git a/html/config.html b/html/setup.html similarity index 83% rename from html/config.html rename to html/setup.html index 2c8b24b..147fcfc 100644 --- a/html/config.html +++ b/html/setup.html @@ -3,41 +3,29 @@ - FilaMan - Configuration + FilaMan - Setup -
-

Device Configuration

+

Device Setup

diff --git a/html/upgrade.html b/html/upgrade.html index d34d4a8..3ecbd75 100644 --- a/html/upgrade.html +++ b/html/upgrade.html @@ -1,4 +1,4 @@ - + @@ -30,8 +30,7 @@
@@ -42,8 +41,6 @@
- -

Firmware Upgrade

@@ -58,7 +55,7 @@
- +
@@ -69,7 +66,7 @@
- +
@@ -82,12 +79,6 @@
- \ No newline at end of file + diff --git a/html/wifi.html b/html/wifi.html index 0ffef42..8dcee67 100644 --- a/html/wifi.html +++ b/html/wifi.html @@ -1,4 +1,4 @@ - + @@ -30,8 +30,7 @@
@@ -42,16 +41,27 @@
- -
-

WiFi Configuration Page

-
-
-
- -
-

Configure your WiFi settings here.

+

WiFi Configuration

+

Your device is connected to WiFi.

+

To change WiFi settings, you can reset the WiFi configuration by holding the hardware button (if available) or using the WiFi manager portal.

+ + diff --git a/src/display.cpp b/src/display.cpp index c515b3d..be9b50b 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -145,7 +145,7 @@ void oledShowMultilineMessage(const String &message, uint8_t size) { display.display(); } -void oledShowMessage(const String &message, uint8_t size) { +void oledDisplayText(const String &message, uint8_t size) { oledcleardata(); display.setTextSize(size); display.setTextWrap(false); @@ -177,19 +177,7 @@ void oledShowTopRow() { // Do not show status indicators during boot if(!booting){ - if(bambuDisabled == false) { - if (bambu_connected == 1) { - display.drawBitmap(50, 0, bitmap_bambu_on , 16, 16, WHITE); - } else { - if(iconToggle){ - display.drawBitmap(50, 0, bitmap_bambu_on , 16, 16, WHITE); - display.drawLine(50, 15, 66, 0, WHITE); - display.drawLine(51, 15, 67, 0, WHITE); - } - } - } - - if (spoolmanConnected) { + if (filamanConnected) { display.drawBitmap(80, 0, bitmap_spoolman_on , 16, 16, WHITE); } else { if(iconToggle){ diff --git a/src/display.h b/src/display.h index c4cdb08..06e55a7 100644 --- a/src/display.h +++ b/src/display.h @@ -19,7 +19,7 @@ int oled_center_v(const String &text); void oledShowProgressBar(const uint8_t step, const uint8_t numSteps, const char* largeText, const char* statusMessage); void oledShowWeight(uint16_t weight); -void oledShowMessage(const String &message, uint8_t size = 2); +void oledDisplayText(const String &message, uint8_t size = 2); void oledShowTopRow(); void oledShowIcon(const char* icon); diff --git a/src/main.cpp b/src/main.cpp index 10e3f82..78a230b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "wlan.h" #include "config.h" @@ -86,6 +88,11 @@ unsigned long lastWeightReadTime = 0; const unsigned long weightReadInterval = 1000; // 1 second unsigned long lastFilamanHeartbeatTime = 0; +unsigned long lastWifiCheckTime = 0; +unsigned long lastTopRowUpdateTime = 0; + +uint8_t weightSend = 0; +int16_t lastWeight = 0; // Button debounce variables unsigned long lastButtonPress = 0; @@ -125,8 +132,8 @@ void loop() { { // Do not show the warning if the calibratin process is onging if(!scaleCalibrationActive){ - oledShowMessage("Scale not calibrated"); - vTaskDelay(1000 / portTICK_PERIOD_MS); + oledDisplayText("Scale not calibrated"); + vTaskDelay(pdMS_TO_TICKS(1000)); } } else @@ -139,7 +146,7 @@ void loop() { int16_t displayWeight = getFilteredDisplayWeight(); if (mainTaskWasPaused || (weight != lastWeight && nfcReaderState == NFC_IDLE)) { - (displayWeight < 2) ? ((displayWeight < -2) ? oledShowMessage("!! -0") : oledShowWeight(0)) : oledShowWeight(displayWeight); + (displayWeight < 2) ? ((displayWeight < -2) ? oledDisplayText("!! -0") : oledShowWeight(0)) : oledShowWeight(displayWeight); } mainTaskWasPaused = false; } diff --git a/src/nfc.cpp b/src/nfc.cpp index 7c931c0..70cd333 100644 --- a/src/nfc.cpp +++ b/src/nfc.cpp @@ -386,7 +386,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { } // Small delay to prevent interface overload - vTaskDelay(5 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(5)); yield(); } @@ -464,8 +464,9 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { Serial.println("!!!!!!!!!!!!!!!!!!!!!!!!"); Serial.println(); - oledShowMessage("Tag zu klein für Payload"); - vTaskDelay(3000 / portTICK_PERIOD_MS); + oledDisplayText("Tag zu klein für Payload"); + vTaskDelay(pdMS_TO_TICKS(3000)); + return 0; } @@ -495,7 +496,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { // Reinitialize the PN532 nfc.begin(); - vTaskDelay(500 / portTICK_PERIOD_MS); // Give it time to initialize + vTaskDelay(pdMS_TO_TICKS(500)); // Give it time to initialize // Check firmware version to ensure communication is working uint32_t versiondata = nfc.getFirmwareVersion(); @@ -505,15 +506,16 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { Serial.println("✓ PN532 Kommunikation wiederhergestellt"); } else { Serial.println("❌ PN532 Kommunikation fehlgeschlagen"); - oledShowMessage("NFC Reset failed"); - vTaskDelay(3000 / portTICK_PERIOD_MS); + oledDisplayText("NFC Reset failed"); + vTaskDelay(pdMS_TO_TICKS(3000)); + return 0; } // Step 2: Reconfigure SAM Serial.println("2. SAM-Konfiguration..."); nfc.SAMConfig(); - vTaskDelay(200 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(200)); // Step 3: Re-detect the tag Serial.println("3. Tag-Wiedererkennung..."); @@ -532,14 +534,15 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { break; } else { Serial.println("❌"); - vTaskDelay(300 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(300)); } } if (!tagRedetected) { Serial.println("❌ Tag konnte nach Reset nicht wiedererkannt werden"); - oledShowMessage("Tag lost after reset"); - vTaskDelay(3000 / portTICK_PERIOD_MS); + oledDisplayText("Tag lost after reset"); + vTaskDelay(pdMS_TO_TICKS(3000)); + return 0; } @@ -547,7 +550,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { // Step 4: Test basic page reading Serial.println("4. Test der Grundfunktionalität..."); - vTaskDelay(200 / portTICK_PERIOD_MS); // Give interface time to stabilize + vTaskDelay(pdMS_TO_TICKS(200)); // Give interface time to stabilize ccReadable = nfc.ntag2xx_ReadPage(3, ccTest); Serial.print("Capability Container nach Reset lesbar: "); @@ -555,8 +558,9 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { if (!ccReadable) { Serial.println("❌ NFC-Interface funktioniert nach Reset immer noch nicht"); - oledShowMessage("NFC still broken"); - vTaskDelay(3000 / portTICK_PERIOD_MS); + oledDisplayText("NFC still broken"); + vTaskDelay(pdMS_TO_TICKS(3000)); + return 0; } @@ -601,14 +605,15 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { basicPagesReadable = false; } } - vTaskDelay(10 / portTICK_PERIOD_MS); // Small delay between reads + vTaskDelay(pdMS_TO_TICKS(10)); // Small delay between reads } if (!basicPagesReadable) { Serial.println("❌ KRITISCHER FEHLER: Grundlegende NDEF-Seiten nicht lesbar!"); Serial.println("Tag oder Interface ist defekt"); - oledShowMessage("Tag/Interface defect"); - vTaskDelay(3000 / portTICK_PERIOD_MS); + oledDisplayText("Tag/Interface defect"); + vTaskDelay(pdMS_TO_TICKS(3000)); + return 0; } @@ -627,8 +632,9 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { // First, read original content of test page if (!nfc.ntag2xx_ReadPage(10, originalPage)) { Serial.println("FEHLER: Kann Testseite nicht lesen für Backup"); - oledShowMessage("Test page read error"); - vTaskDelay(3000 / portTICK_PERIOD_MS); + oledDisplayText("Test page read error"); + vTaskDelay(pdMS_TO_TICKS(3000)); + return 0; } @@ -657,26 +663,28 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { if (!tagStillPresent) { Serial.println("URSACHE: Tag wurde während Schreibtest entfernt!"); - oledShowMessage("Tag removed"); + oledDisplayText("Tag removed"); } else { Serial.println("URSACHE: Tag ist vorhanden aber nicht beschreibbar"); Serial.println("Möglicherweise: Schreibschutz, Defekt, oder Interface-Problem"); - oledShowMessage("Tag write protected?"); + oledDisplayText("Tag write protected?"); } Serial.println("=========================================="); - vTaskDelay(3000 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(3000)); + return 0; } // Verify test write uint8_t readBack[4]; - vTaskDelay(20 / portTICK_PERIOD_MS); // Wait for write to complete + vTaskDelay(pdMS_TO_TICKS(20)); // Wait for write to complete if (!nfc.ntag2xx_ReadPage(10, readBack)) { Serial.println("FEHLER: Kann Testdaten nicht zurücklesen!"); - oledShowMessage("Test verify failed"); - vTaskDelay(3000 / portTICK_PERIOD_MS); + oledDisplayText("Test verify failed"); + vTaskDelay(pdMS_TO_TICKS(3000)); + return 0; } @@ -719,8 +727,8 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { Serial.println("=== SCHRITT 4: NDEF-INITIALISIERUNG ==="); if (!initializeNdefStructure()) { Serial.println("FEHLER: Konnte NDEF-Struktur nicht initialisieren!"); - oledShowMessage("NDEF init failed"); - vTaskDelay(2000 / portTICK_PERIOD_MS); + oledDisplayText("NDEF init failed"); + vTaskDelay(pdMS_TO_TICKS(2000)); return 0; } @@ -753,7 +761,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { Serial.println("Stabilisiere NFC-Interface vor Hauptschreibvorgang..."); // Give the interface time to fully settle after NDEF initialization - vTaskDelay(200 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(200)); // Test interface stability with a simple read uint8_t stabilityTest[4]; @@ -769,14 +777,15 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { Serial.print("Interface stability test "); Serial.print(attempts + 1); Serial.println("/3: ❌"); - vTaskDelay(100 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(100)); } } if (!interfaceStable) { Serial.println("FEHLER: NFC-Interface ist nicht stabil genug für Schreibvorgang"); - oledShowMessage("NFC Interface unstable"); - vTaskDelay(3000 / portTICK_PERIOD_MS); + oledDisplayText("NFC Interface unstable"); + vTaskDelay(pdMS_TO_TICKS(3000)); + return 0; } @@ -787,8 +796,8 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { uint8_t* tlvData = (uint8_t*) malloc(totalTlvSize); if (tlvData == NULL) { Serial.println("Fehler: Nicht genug Speicher für TLV-Daten vorhanden."); - oledShowMessage("Memory error"); - vTaskDelay(2000 / portTICK_PERIOD_MS); + oledDisplayText("Memory error"); + vTaskDelay(pdMS_TO_TICKS(2000)); return 0; } @@ -881,7 +890,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { Serial.println(" fehlgeschlagen"); if (writeAttempt < 2) { - vTaskDelay(50 / portTICK_PERIOD_MS); // Wait before retry + vTaskDelay(pdMS_TO_TICKS(50)); // Wait before retry } } } @@ -911,7 +920,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { Serial.print("... "); uint8_t verifyBuffer[4]; - vTaskDelay(20 / portTICK_PERIOD_MS); // Increased delay before verification + vTaskDelay(pdMS_TO_TICKS(20)); // Increased delay before verification // Verification with retry mechanism bool verifySuccess = false; @@ -939,14 +948,14 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { Serial.print("Verifikationsversuch "); Serial.print(verifyAttempt + 1); Serial.println("/3 fehlgeschlagen, wiederhole..."); - vTaskDelay(30 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(30)); } } else { Serial.print("Verifikations-Read-Versuch "); Serial.print(verifyAttempt + 1); Serial.println("/3 fehlgeschlagen"); if (verifyAttempt < 2) { - vTaskDelay(30 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(30)); } } } @@ -973,7 +982,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { pageNumber++; yield(); - vTaskDelay(10 / portTICK_PERIOD_MS); // Slightly increased delay between page writes + vTaskDelay(pdMS_TO_TICKS(10)); // Slightly increased delay between page writes } free(tlvData); @@ -1006,7 +1015,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { Serial.println("Stabilisiere NFC-Interface nach Schreibvorgang..."); // Give the tag and interface time to settle after write operation - vTaskDelay(300 / portTICK_PERIOD_MS); // Increased stabilization time + vTaskDelay(pdMS_TO_TICKS(300)); // Increased stabilization time // Test if the interface is still responsive uint8_t postWriteTest[4]; @@ -1026,7 +1035,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { if (stabilityAttempt < 4) { Serial.println("Warte und versuche Interface zu stabilisieren..."); - vTaskDelay(200 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(200)); // Try to re-establish communication with a simple tag presence check uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; @@ -1056,7 +1065,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { } bool decodeNdefAndReturnJson(const byte* encodedMessage, String uidString) { - oledShowProgressBar(1, octoEnabled?5:4, "Reading", "Decoding data"); + oledShowProgressBar(1, 4, "Reading", "Decoding data"); // Debug: Print first 32 bytes of the raw data Serial.println("Raw NDEF data (first 32 bytes):"); @@ -1253,6 +1262,7 @@ bool decodeNdefAndReturnJson(const byte* encodedMessage, String uidString) { activeSpoolId = doc["sm_id"].as(); lastSpoolId = activeSpoolId; } + else if(doc["location_id"].is()) { Serial.println("Location Tag found!"); @@ -1573,10 +1583,9 @@ void writeJsonToTag(void *parameter) { // Just use nfcWriteInProgress to prevent scanning and fast-path operations Serial.println("NFC Write Task starting - High-level operations blocked, low-level NFC available"); - //pauseBambuMqttTask = true; // aktualisieren der Website wenn sich der Status ändert sendNfcData(); - vTaskDelay(100 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(100)); // Show waiting message for tag detection oledShowProgressBar(0, 1, "Write Tag", "Warte auf Tag"); @@ -1617,43 +1626,13 @@ void writeJsonToTag(void *parameter) { if (success) { Serial.println("NDEF-Message erfolgreich auf den Tag geschrieben"); - //oledShowMessage("NFC-Tag written"); - //vTaskDelay(1000 / portTICK_PERIOD_MS); + //oledDisplayText("NFC-Tag written"); + //vTaskDelay(pdMS_TO_TICKS(1000)); nfcReaderState = NFC_WRITE_SUCCESS; // aktualisieren der Website wenn sich der Status ändert sendNfcData(); - pauseBambuMqttTask = false; - if(params->tagType){ - // TBD: should this be simplified? - if (updateSpoolTagId(uidString, params->payload) && params->tagType) { - // Check if weight is over 20g and send to Spoolman - if (weight > 20) { - Serial.println("Tag successfully written and weight > 20g - sending weight to Spoolman"); - - // Extract spool ID from payload for weight update - JsonDocument payloadDoc; - DeserializationError error = deserializeJson(payloadDoc, params->payload); - - if (!error && payloadDoc["sm_id"].is()) { - String spoolId = payloadDoc["sm_id"].as(); - if (spoolId != "") { - Serial.printf("Updating spool %s with weight %dg\n", spoolId.c_str(), weight); - updateSpoolWeight(spoolId, weight); - } else { - Serial.println("No valid spool ID found for weight update"); - } - } else { - Serial.println("Error parsing payload for spool ID extraction"); - } - - payloadDoc.clear(); - } else { - Serial.printf("Weight %dg is not above 20g threshold - skipping weight update\n", weight); - } - }else{ - // Potentially handle errors - } + oledShowProgressBar(1, 1, "Write Tag", "Done!"); }else{ oledShowProgressBar(1, 1, "Write Tag", "Done!"); } @@ -1663,7 +1642,7 @@ void writeJsonToTag(void *parameter) { Serial.println("=== POST-WRITE NFC STABILIZATION ==="); // Wait for tag operations to complete - vTaskDelay(500 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(500)); // Test tag presence and remove detection uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; @@ -1689,7 +1668,7 @@ void writeJsonToTag(void *parameter) { Serial.print(tagRemovalChecks); Serial.println("/10)"); - vTaskDelay(500 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(500)); } if (tagRemovalChecks >= 10) { @@ -1698,7 +1677,7 @@ void writeJsonToTag(void *parameter) { // Additional interface stabilization before resuming normal operations Serial.println("Stabilisiere NFC-Interface für normale Operationen..."); - vTaskDelay(200 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(200)); // Test if interface is ready for normal scanning uint8_t interfaceTestBuffer[4]; @@ -1719,7 +1698,7 @@ void writeJsonToTag(void *parameter) { break; } else { Serial.println("❌"); - vTaskDelay(100 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(100)); } } @@ -1732,13 +1711,13 @@ void writeJsonToTag(void *parameter) { Serial.println("========================================="); vTaskResume(RfidReaderTask); - vTaskDelay(500 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(500)); } else { Serial.println("Fehler beim Schreiben der NDEF-Message auf den Tag"); oledShowIcon("failed"); - vTaskDelay(2000 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(2000)); nfcReaderState = NFC_WRITE_ERROR; } } @@ -1746,7 +1725,7 @@ void writeJsonToTag(void *parameter) { { Serial.println("Fehler: Kein Tag zu schreiben gefunden."); oledShowProgressBar(1, 1, "Failure!", "No tag found"); - vTaskDelay(2000 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(2000)); nfcReaderState = NFC_IDLE; } @@ -1892,7 +1871,10 @@ void scanRfidTask(void * parameter) { if (!success) { activeSpoolId = ""; activeTagUuid = ""; + Serial.println("Tag entfernt"); + oledShowWeight(weight); } + // As long as there is still a tag on the reader, do not try to read it again if (success && nfcReaderState == NFC_IDLE) @@ -1909,7 +1891,7 @@ void scanRfidTask(void * parameter) { // Reduced stabilization time for better responsiveness Serial.println("Tag detected, minimal stabilization..."); - vTaskDelay(200 / portTICK_PERIOD_MS); // Reduced from 1000ms to 200ms + vTaskDelay(pdMS_TO_TICKS(200)); // Reduced from 1000ms to 200ms // create Tag UID string String uidString = ""; @@ -1927,7 +1909,6 @@ void scanRfidTask(void * parameter) { // Try fast-path detection first for known spools if (quickSpoolIdCheck(uidString)) { Serial.println("✓ FAST-PATH: Tag processed quickly, skipping full read"); - pauseBambuMqttTask = false; // Set reader back to idle for next scan nfcReaderState = NFC_READ_SUCCESS; delay(500); // Small delay before next scan @@ -2012,9 +1993,11 @@ void scanRfidTask(void * parameter) { //uidString = ""; nfcJsonData = ""; activeSpoolId = ""; + activeTagUuid = ""; Serial.println("Tag entfernt"); - if (!bambuCredentials.autosend_enable) oledShowWeight(weight); + oledShowWeight(weight); } + // Reset state after successful read when tag is removed else if (!success && nfcReaderState == NFC_READ_SUCCESS) { @@ -2025,10 +2008,12 @@ void scanRfidTask(void * parameter) { // Add a pause after successful reading to prevent immediate re-reading if (nfcReaderState == NFC_READ_SUCCESS) { Serial.println("Tag erfolgreich gelesen - warte 3 Sekunden vor nächstem Scan"); - vTaskDelay(3000 / portTICK_PERIOD_MS); // Reduced from 5 seconds to 3 seconds + vTaskDelay(pdMS_TO_TICKS(3000)); + // Reduced from 5 seconds to 3 seconds } else { // Faster scanning when no tag or idle state - vTaskDelay(150 / portTICK_PERIOD_MS); // Faster scan interval + vTaskDelay(pdMS_TO_TICKS(150)); + // Faster scan interval } // aktualisieren der Website wenn sich der Status ändert @@ -2042,11 +2027,11 @@ void scanRfidTask(void * parameter) { if (nfcWriteInProgress) { // During write: Just pause scanning, don't disable NFC interface // Serial.println("NFC Scanning paused during write operation"); - vTaskDelay(100 / portTICK_PERIOD_MS); // Shorter delay during write + vTaskDelay(pdMS_TO_TICKS(100)); // Shorter delay during write } else { // Full suspension requested Serial.println("NFC Reading disabled"); - vTaskDelay(1000 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(1000)); } } yield(); @@ -2061,8 +2046,8 @@ void startNfc() { unsigned long versiondata = nfc.getFirmwareVersion(); // Lese Versionsnummer der Firmware aus if (! versiondata) { // Wenn keine Antwort kommt Serial.println("Kann kein RFID Board finden !"); // Sende Text "Kann kein..." an seriellen Monitor - oledShowMessage("No RFID Board found"); - vTaskDelay(2000 / portTICK_PERIOD_MS); + oledDisplayText("No RFID Board found"); + vTaskDelay(pdMS_TO_TICKS(2000)); } else { Serial.print("Chip PN5 gefunden"); Serial.println((versiondata >> 24) & 0xFF, HEX); // Sende Text und Versionsinfos an seriellen diff --git a/src/ota.cpp b/src/ota.cpp index 630974e..f6e7601 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -6,8 +6,7 @@ // Globale Variablen für Config Backups hinzufügen -String bambuCredentialsBackup; -String spoolmanUrlBackup; +String filamanConfigBackup; // Globale Variable für den Update-Typ static int currentUpdateCommand = 0; @@ -56,7 +55,7 @@ void restoreJsonConfigs() { void espRestart() { yield(); - vTaskDelay(5000 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(5000)); ESP.restart(); } @@ -137,9 +136,9 @@ void handleUpdate(AsyncWebServer &server) { if (isSpiffsUpdate) { // Backup vor dem Update sendUpdateProgress(0, "backup", "Backing up configurations..."); - vTaskDelay(200 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(200)); backupJsonConfigs(); - vTaskDelay(200 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(200)); const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL); if (!partition || !Update.begin(partition->size, U_SPIFFS)) { @@ -147,14 +146,14 @@ void handleUpdate(AsyncWebServer &server) { return; } sendUpdateProgress(5, "starting", "Starting SPIFFS update..."); - vTaskDelay(200 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(200)); } else { if (!Update.begin(updateTotalSize)) { request->send(400, "application/json", "{\"success\":false,\"message\":\"Update initialization failed\"}"); return; } sendUpdateProgress(0, "starting", "Starting firmware update..."); - vTaskDelay(200 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(200)); } } @@ -180,7 +179,7 @@ void handleUpdate(AsyncWebServer &server) { if (currentProgress != lastProgress && (currentProgress % 10 == 0 || final)) { sendUpdateProgress(currentProgress, "uploading"); oledShowProgressBar(currentProgress, 100, "Update", "Download"); - vTaskDelay(50 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(50)); lastProgress = currentProgress; } } @@ -204,7 +203,7 @@ void handleUpdate(AsyncWebServer &server) { // Erste 100% Nachricht ws.textAll("{\"type\":\"updateProgress\",\"progress\":100,\"status\":\"success\",\"message\":\"Update successful! Restarting device...\"}"); - vTaskDelay(2000 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(2000)); AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"success\":true,\"message\":\"Update successful! Restarting device...\"}"); diff --git a/src/scale.cpp b/src/scale.cpp index e47d8e1..21a74d8 100644 --- a/src/scale.cpp +++ b/src/scale.cpp @@ -167,7 +167,7 @@ void scale_loop(void * parameter) { if (scaleTareRequest == true || (autoTare && scale_tare_counter >= 20)) { Serial.println("Re-Tare scale"); - oledShowMessage("TARE Scale"); + oledDisplayText("TARE Scale"); vTaskDelay(pdMS_TO_TICKS(1000)); scale.tare(); resetWeightFilter(); // Reset filter after manual tare @@ -382,7 +382,7 @@ uint8_t calibrate_scale() { { Serial.println("HX711 not found."); - oledShowMessage("HX711 not found"); + oledDisplayText("HX711 not found"); for (uint16_t i = 0; i < 30000; i++) { yield(); diff --git a/src/website.cpp b/src/website.cpp index 7504c80..43d3454 100644 --- a/src/website.cpp +++ b/src/website.cpp @@ -171,12 +171,10 @@ void setupWebserver(AsyncWebServer &server) { loadFilamanConfig(); - // Route für about - server.on("/about", HTTP_GET, [](AsyncWebServerRequest *request){ - AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/index.html.gz", "text/html"); - response->addHeader("Content-Encoding", "gzip"); - response->addHeader("Cache-Control", CACHE_CONTROL); - request->send(response); + // Route für Start (Index) + server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ + String html = loadHtmlWithHeader("/index.html"); + request->send(200, "text/html", html); }); // Route für Waage @@ -186,17 +184,9 @@ void setupWebserver(AsyncWebServer &server) { request->send(200, "text/html", html); }); - // Route für RFID - server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ - AsyncWebServerResponse *response = request->beginResponse(LittleFS, "/rfid.html.gz", "text/html"); - response->addHeader("Content-Encoding", "gzip"); - response->addHeader("Cache-Control", CACHE_CONTROL); - request->send(response); - }); - - // Route für Config & Registration - server.on("/config", HTTP_GET, [](AsyncWebServerRequest *request){ - String html = loadHtmlWithHeader("/config.html"); + // Route für Setup & Registration + server.on("/setup", HTTP_GET, [](AsyncWebServerRequest *request){ + String html = loadHtmlWithHeader("/setup.html"); html.replace("{{filamanUrl}}", filamanUrl); html.replace("{{registered}}", filamanRegistered ? "Yes" : "No"); request->send(200, "text/html", html); @@ -227,7 +217,7 @@ void setupWebserver(AsyncWebServer &server) { String payloadString; serializeJson(doc, payloadString); - bool isSpool = doc.containsKey("spool_id"); + bool isSpool = !doc["spool_id"].isNull(); startWriteJsonToTag(isSpool, payloadString.c_str()); request->send(200, "application/json", "{\"status\": \"writing\"}"); diff --git a/src/website.h b/src/website.h index b69f819..61a2d4c 100644 --- a/src/website.h +++ b/src/website.h @@ -8,7 +8,6 @@ #include #include #include -#include "bambu.h" #include "nfc.h" #include "scale.h" #include "esp_task_wdt.h" diff --git a/src/wlan.cpp b/src/wlan.cpp index 9dceeb2..09ff61f 100644 --- a/src/wlan.cpp +++ b/src/wlan.cpp @@ -33,7 +33,7 @@ void startMDNS() { if (!MDNS.begin("filaman")) { Serial.println("Error setting up MDNS responder!"); while(1) { - vTaskDelay(1000 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(1000)); } } MDNS.addService("http", "tcp", 80); @@ -43,7 +43,7 @@ void startMDNS() { void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("Entered config mode"); oledShowTopRow(); - oledShowMessage("WiFi Config Mode"); + oledDisplayText("WiFi Config Mode"); } void initWiFi() { @@ -69,7 +69,7 @@ void initWiFi() { Serial.println("Failed to connect or hit timeout"); // ESP.restart(); oledShowTopRow(); - oledShowMessage("WiFi not connected Check Portal"); + oledDisplayText("WiFi not connected Check Portal"); } else { wifiOn = true; @@ -92,15 +92,15 @@ void checkWiFiConnection() { Serial.println("WiFi connection lost. Reconnecting..."); wifiOn = false; oledShowTopRow(); - oledShowMessage("WiFi reconnecting"); + oledDisplayText("WiFi reconnecting"); WiFi.reconnect(); // Versuche, die Verbindung wiederherzustellen - vTaskDelay(5000 / portTICK_PERIOD_MS); // Warte 5 Sekunden, bevor erneut geprüft wird + vTaskDelay(pdMS_TO_TICKS(5000)); // Warte 5 Sekunden, bevor erneut geprüft wird if (WiFi.status() != WL_CONNECTED) { Serial.println("Failed to reconnect. Restarting WiFi..."); WiFi.disconnect(); Serial.println("WiFi disconnected."); - vTaskDelay(1000 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(1000)); wifiErrorCounter++; //wifiSettings();