From b5c014db86d16afcd0e1b9c1811483bd59cddfed Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Tue, 18 Feb 2025 12:28:47 +0100 Subject: [PATCH] feat: update version to 1.2.2; change OTA upgrade link in HTML files; enhance OTA upload handling with progress updates and JSON responses --- html/header.html | 2 +- html/index.html | 2 +- html/rfid.html | 2 +- html/spoolman.html | 2 +- html/style.css | 74 +++++++++++++++++++++++ html/upgrade.html | 142 +++++++++++++++++++++++++++++++++++++++++++++ html/waage.html | 2 +- html/wifi.html | 2 +- platformio.ini | 2 +- src/ota.cpp | 23 +++++--- src/website.cpp | 101 ++------------------------------ 11 files changed, 244 insertions(+), 110 deletions(-) create mode 100644 html/upgrade.html diff --git a/html/header.html b/html/header.html index 84607ae..b04a2bc 100644 --- a/html/header.html +++ b/html/header.html @@ -21,7 +21,7 @@ Scale Spoolman/Bambu About - Upgrade + Upgrade
diff --git a/html/index.html b/html/index.html index 00d2cf7..6325bcf 100644 --- a/html/index.html +++ b/html/index.html @@ -21,7 +21,7 @@ Scale Spoolman/Bambu About - Upgrade + Upgrade
diff --git a/html/rfid.html b/html/rfid.html index f5f31ad..e1a9d74 100644 --- a/html/rfid.html +++ b/html/rfid.html @@ -21,7 +21,7 @@ Scale Spoolman/Bambu About - Upgrade + Upgrade
diff --git a/html/spoolman.html b/html/spoolman.html index 19b21ff..8745fa7 100644 --- a/html/spoolman.html +++ b/html/spoolman.html @@ -21,7 +21,7 @@ Scale Spoolman/Bambu About - Upgrade + Upgrade
diff --git a/html/style.css b/html/style.css index c69c48f..ebe23f5 100644 --- a/html/style.css +++ b/html/style.css @@ -1013,4 +1013,78 @@ input[type="submit"]:disabled, color: #000; vertical-align: middle; margin-left: 0.5rem; +} + +.progress-container { + width: 100%; + margin: 20px 0; + display: none; + background: #f0f0f0; + border-radius: 4px; + overflow: hidden; +} +.progress-bar { + width: 0%; + height: 24px; + background-color: #4CAF50; + text-align: center; + line-height: 24px; + color: white; + transition: width 0.3s ease-in-out; + font-weight: bold; +} +.status { + margin: 10px 0; + padding: 15px; + border-radius: 4px; + display: none; +} +.error { + background-color: #ffebee; + color: #c62828; + border: 1px solid #ef9a9a; +} +.success { + background-color: #e8f5e9; + color: #2e7d32; + border: 1px solid #a5d6a7; +} +.update-form { + background: var(--primary-color); + padding: 20px; + border-radius: 8px; + box-shadow: 0 2px 4px rgba(0,0,0,0.1); + margin: 0 auto; + width: 400px; +} +.update-form input[type="file"] { + margin-bottom: 15px; + width: 80%; + padding: 8px; + border: 1px solid #ddd; + border-radius: 4px; +} +.update-form input[type="submit"] { + background-color: #4CAF50; + color: white; + padding: 10px 20px; + border: none; + border-radius: 4px; + cursor: pointer; + font-size: 16px; +} +.update-form input[type="submit"]:hover { + background-color: #45a049; +} +.update-form input[type="submit"]:disabled { + background-color: #cccccc; + cursor: not-allowed; +} +.warning { + background-color: var(--primary-color); + border: 1px solid #ffe0b2; + color: #e65100; + padding: 15px; + margin: 20px 0; + border-radius: 4px; } \ No newline at end of file diff --git a/html/upgrade.html b/html/upgrade.html new file mode 100644 index 0000000..5d7612f --- /dev/null +++ b/html/upgrade.html @@ -0,0 +1,142 @@ + + + + + + + FilaMan - Filament Management Tool + + + + + + + + +
+

Firmware Upgrade

+ +
+ Warning: Please do not turn off or restart the device during the update. + Configuration files will be automatically backed up and restored after the update. +
+ + +
+
+ + + +
+ +
+
0%
+
+
+
+ + + + \ No newline at end of file diff --git a/html/waage.html b/html/waage.html index a2f2a75..4799cca 100644 --- a/html/waage.html +++ b/html/waage.html @@ -21,7 +21,7 @@ Scale Spoolman/Bambu About - Upgrade + Upgrade
diff --git a/html/wifi.html b/html/wifi.html index cda0883..6ff8add 100644 --- a/html/wifi.html +++ b/html/wifi.html @@ -21,7 +21,7 @@ Scale Spoolman/Bambu About - Upgrade + Upgrade
diff --git a/platformio.ini b/platformio.ini index df5bfcd..b6c4236 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [common] -version = "1.2.1" +version = "1.2.2" [env:esp32dev] platform = espressif32 diff --git a/src/ota.cpp b/src/ota.cpp index 309b7ec..6503f18 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -127,10 +127,12 @@ bool restoreConfigs() { void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { static bool updateStarted = false; static size_t totalBytes = 0; + static size_t totalSize = 0; if (!index) { updateStarted = false; totalBytes = 0; + totalSize = request->contentLength(); // Check minimum heap size if (ESP.getFreeHeap() < MIN_FREE_HEAP) { @@ -138,13 +140,12 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind return; } - size_t updateSize = request->contentLength(); - if (updateSize == 0) { + if (totalSize == 0) { request->send(400, "text/plain", "Invalid file size"); return; } - Serial.printf("Update size: %u bytes\n", updateSize); + Serial.printf("Update size: %u bytes\n", totalSize); Serial.printf("Free space: %u bytes\n", ESP.getFreeSketchSpace()); Serial.printf("Free heap: %u bytes\n", ESP.getFreeHeap()); @@ -158,7 +159,7 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind SPIFFS.end(); // Begin update with minimal configuration - if (!Update.begin(updateSize)) { + if (!Update.begin(totalSize)) { Serial.printf("Update.begin failed: %s\n", Update.errorString()); request->send(500, "text/plain", "Failed to start update"); return; @@ -166,6 +167,9 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind updateStarted = true; Serial.println("Update process started"); + + // Send initial progress + request->send(200, "text/plain", "0"); } if (!updateStarted) { @@ -182,8 +186,11 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind } totalBytes += len; - if (totalBytes % (32 * 1024) == 0) { - Serial.printf("Progress: %u bytes\n", totalBytes); + + // Send progress update + if (!final) { + int progress = (totalBytes * 100) / totalSize; + request->send(200, "text/plain", String(progress)); } if (final) { @@ -196,7 +203,7 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind // Try to restore configs if (!SPIFFS.begin(true)) { Serial.println("Failed to mount SPIFFS for restore"); - request->send(200, "text/plain", "Update successful but config restore failed. Device will restart..."); + request->send(200, "application/json", "{\"status\": \"success\", \"message\": \"Update successful but config restore failed. Device will restart...\", \"restart\": true}"); delay(2000); ESP.restart(); return; @@ -206,7 +213,7 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind Serial.println("Failed to restore configs"); } - request->send(200, "text/plain", "Update successful. Device will restart..."); + request->send(200, "application/json", "{\"status\": \"success\", \"message\": \"Update successful! Device will restart...\", \"restart\": true}"); delay(2000); ESP.restart(); } diff --git a/src/website.cpp b/src/website.cpp index d4d762d..ac706ed 100644 --- a/src/website.cpp +++ b/src/website.cpp @@ -338,101 +338,12 @@ void setupWebserver(AsyncWebServer &server) { Serial.println("RFID.js gesendet"); }); - // Route für OTA Updates - server.on("/ota", HTTP_GET, [](AsyncWebServerRequest *request) { - Serial.println("Anfrage für /ota erhalten"); - - String html = R"( - - - - Firmware Update - - - - -

Firmware Update

-
- - -
-
-
0%
-
-
- - - - )"; - request->send(200, "text/html", html); + // Route für Firmware Update + server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest *request) { + AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/upgrade.html.gz", "text/html"); + response->addHeader("Content-Encoding", "gzip"); + response->addHeader("Cache-Control", CACHE_CONTROL); + request->send(response); }); server.on("/update", HTTP_POST,