refactor: streamline Gitea release workflow and remove obsolete OTA data initialization script

This commit is contained in:
2025-02-20 15:41:14 +01:00
parent 6391054c23
commit cce39319d9
4 changed files with 61 additions and 127 deletions

View File

@ -7,7 +7,6 @@
#include "scale.h"
#include "nfc.h"
const uint8_t ESP_MAGIC = 0xE9;
static bool tasksAreStopped = false;
void stopAllTasks() {
@ -23,7 +22,6 @@ void stopAllTasks() {
void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
static size_t contentLength = 0;
static bool isFullImage = false;
if (!index) {
contentLength = request->contentLength();
@ -34,43 +32,37 @@ void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t ind
return;
}
// Bei full.bin muss das Magic Byte nicht geprüft werden
isFullImage = (contentLength > 0x300000);
if (!isFullImage && data[0] != ESP_MAGIC) {
Serial.printf("Wrong magic byte: 0x%02X (expected 0x%02X)\n", data[0], ESP_MAGIC);
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Invalid firmware format\"}");
return;
}
// Stoppe alle Tasks vor dem Update
if (!tasksAreStopped && (RfidReaderTask || BambuMqttTask || ScaleTask)) {
stopAllTasks();
tasksAreStopped = true;
}
if (!Update.begin(contentLength, isFullImage ? U_FLASH : U_FLASH)) {
// Für full.bin keine Magic Byte Prüfung
bool isFullImage = (contentLength > 0x300000);
if (!isFullImage && data[0] != 0xE9) {
Serial.printf("Wrong magic byte: 0x%02X (expected 0xE9)\n", data[0]);
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Invalid firmware format\"}");
return;
}
// Bei full.bin UPDATE_SIZE_UNKNOWN verwenden
if (!Update.begin(isFullImage ? UPDATE_SIZE_UNKNOWN : contentLength)) {
Update.printError(Serial);
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"OTA could not begin\"}");
return;
}
Serial.printf("Starting %s update\n", isFullImage ? "full" : "firmware");
}
// Debug output für die ersten paar Bytes
if (index == 0) {
Serial.printf("First bytes: ");
for(size_t i = 0; i < min(16UL, len); i++) {
Serial.printf("%02X ", data[i]);
}
Serial.println();
}
// Schreibe Update-Daten
if (Update.write(data, len) != len) {
Update.printError(Serial);
request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"OTA write failed\"}");
return;
}
// Update abschließen
if (final) {
if (!Update.end(true)) {
Update.printError(Serial);