fix(server): defer 0xFF OTA confirm to fix race condition
This commit is contained in:
parent
5fe5879873
commit
84e6ca8100
1 changed files with 10 additions and 1 deletions
11
src/main.cpp
11
src/main.cpp
|
|
@ -70,6 +70,7 @@ bool otaShaStarted = false;
|
|||
bool otaReady = false;
|
||||
bool otaEnded = false;
|
||||
bool otaConfirmed = false;
|
||||
bool otaEarlyConfirm = false;
|
||||
uint32_t otaEndedAt = 0;
|
||||
#define OTA_CONFIRM_TIMEOUT_MS 10000
|
||||
|
||||
|
|
@ -191,6 +192,7 @@ static void otaReset() {
|
|||
otaReady = false;
|
||||
otaEnded = false;
|
||||
otaConfirmed = false;
|
||||
otaEarlyConfirm = false;
|
||||
if (otaShaStarted) {
|
||||
mbedtls_sha256_free(&otaShaCtx);
|
||||
otaShaStarted = false;
|
||||
|
|
@ -296,7 +298,8 @@ class OtaCharacteristicCallbacks : public NimBLECharacteristicCallbacks {
|
|||
Serial.printf("OTA: 0xFF received — otaReady=%d, otaEnded=%d, otaConfirmed=%d, otaInProgress=%d\n",
|
||||
otaReady, otaEnded, otaConfirmed, otaInProgress);
|
||||
if (!otaEnded) {
|
||||
Serial.println("OTA: 0xFF IGNORED — otaEnded is false (esp_ota_end not yet called or failed)");
|
||||
Serial.println("OTA: 0xFF arrived early (esp_ota_end not yet called), deferring");
|
||||
otaEarlyConfirm = true;
|
||||
return;
|
||||
}
|
||||
Serial.println("OTA: 0xFF confirm accepted, setting otaConfirmed=true");
|
||||
|
|
@ -550,6 +553,12 @@ void loop() {
|
|||
otaReady, otaEnded, otaConfirmed, otaInProgress);
|
||||
}
|
||||
|
||||
if (otaEnded && otaEarlyConfirm) {
|
||||
Serial.println("OTA: processing deferred 0xFF confirm");
|
||||
otaConfirmed = true;
|
||||
otaEarlyConfirm = false;
|
||||
}
|
||||
|
||||
if (otaEnded && !otaConfirmed && (millis() - otaEndedAt > OTA_CONFIRM_TIMEOUT_MS)) {
|
||||
Serial.printf("OTA: 0xFF confirm timeout (%lu ms) — discarding update, resuming normal operation\n",
|
||||
millis() - otaEndedAt);
|
||||
|
|
|
|||
Loading…
Reference in a new issue