refactor: enhance OTA update process with improved size checks and debugging output
This commit is contained in:
parent
463eaf4b6f
commit
5f52775984
29
src/ota.cpp
29
src/ota.cpp
@ -29,12 +29,6 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind
|
|||||||
static bool isFullImage = false;
|
static bool isFullImage = false;
|
||||||
static uint32_t currentOffset = 0;
|
static uint32_t currentOffset = 0;
|
||||||
|
|
||||||
// Offset-Definitionen aus dem Workflow
|
|
||||||
static const uint32_t BOOTLOADER_OFFSET = 0x1000;
|
|
||||||
static const uint32_t PARTITIONS_OFFSET = 0x8000;
|
|
||||||
static const uint32_t FIRMWARE_OFFSET = 0x10000;
|
|
||||||
static const uint32_t SPIFFS_OFFSET = 0x3D0000;
|
|
||||||
|
|
||||||
if (!index) {
|
if (!index) {
|
||||||
contentLength = request->contentLength();
|
contentLength = request->contentLength();
|
||||||
Serial.printf("Update size: %u bytes\n", contentLength);
|
Serial.printf("Update size: %u bytes\n", contentLength);
|
||||||
@ -44,26 +38,26 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop all tasks to save resources
|
|
||||||
if (!tasksAreStopped && (RfidReaderTask || BambuMqttTask || ScaleTask)) {
|
if (!tasksAreStopped && (RfidReaderTask || BambuMqttTask || ScaleTask)) {
|
||||||
stopAllTasks();
|
stopAllTasks();
|
||||||
tasksAreStopped = true;
|
tasksAreStopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
isFullImage = (contentLength > SPIFFS_OFFSET);
|
// Erweiterte Größenprüfung für full.bin
|
||||||
|
isFullImage = (contentLength >= 0x400000); // 4MB full image
|
||||||
|
|
||||||
if (!isFullImage) {
|
if (!isFullImage) {
|
||||||
// Regular firmware update
|
|
||||||
if (!Update.begin(contentLength)) {
|
if (!Update.begin(contentLength)) {
|
||||||
Serial.printf("Not enough space: %u required\n", contentLength);
|
Serial.printf("Not enough space for firmware: %u required\n", contentLength);
|
||||||
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Not enough space available\"}");
|
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Not enough space available\"}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Serial.println("Firmware update started");
|
Serial.println("Firmware update started");
|
||||||
} else {
|
} else {
|
||||||
// Full image update - start with bootloader
|
// Sicherstellen, dass genügend Flash-Speicher verfügbar ist
|
||||||
if (!Update.begin(contentLength, U_FLASH)) {
|
if(!Update.begin(0x400000, U_FLASH)) { // 4MB Gesamtgröße
|
||||||
Serial.printf("Not enough space for full image: %u required\n", contentLength);
|
Serial.println("Could not begin full image update");
|
||||||
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Not enough space available\"}");
|
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Could not start full update\"}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Serial.println("Full image update started");
|
Serial.println("Full image update started");
|
||||||
@ -71,11 +65,16 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind
|
|||||||
currentOffset = 0;
|
currentOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write data
|
// Zusätzliche Debug-Ausgaben
|
||||||
|
if (isFullImage) {
|
||||||
|
Serial.printf("Writing at offset: 0x%X, length: %u\n", currentOffset, len);
|
||||||
|
}
|
||||||
|
|
||||||
if (Update.write(data, len) != len) {
|
if (Update.write(data, len) != len) {
|
||||||
String errorMsg = Update.errorString();
|
String errorMsg = Update.errorString();
|
||||||
if (errorMsg != "No Error") {
|
if (errorMsg != "No Error") {
|
||||||
Update.printError(Serial);
|
Update.printError(Serial);
|
||||||
|
Serial.printf("Error at offset: 0x%X\n", currentOffset);
|
||||||
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Error writing update: " + errorMsg + "\"}");
|
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Error writing update: " + errorMsg + "\"}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,12 @@
|
|||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
|
||||||
|
// Update size unknown constant, falls nicht bereits definiert
|
||||||
|
#ifndef UPDATE_SIZE_UNKNOWN
|
||||||
|
#define UPDATE_SIZE_UNKNOWN 0xFFFFFFFF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void stopAllTasks();
|
||||||
void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user