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
-
-
-
-
-
-
- )";
- 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,