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 otaReady = false;
|
||||||
bool otaEnded = false;
|
bool otaEnded = false;
|
||||||
bool otaConfirmed = false;
|
bool otaConfirmed = false;
|
||||||
|
bool otaEarlyConfirm = false;
|
||||||
uint32_t otaEndedAt = 0;
|
uint32_t otaEndedAt = 0;
|
||||||
#define OTA_CONFIRM_TIMEOUT_MS 10000
|
#define OTA_CONFIRM_TIMEOUT_MS 10000
|
||||||
|
|
||||||
|
|
@ -191,6 +192,7 @@ static void otaReset() {
|
||||||
otaReady = false;
|
otaReady = false;
|
||||||
otaEnded = false;
|
otaEnded = false;
|
||||||
otaConfirmed = false;
|
otaConfirmed = false;
|
||||||
|
otaEarlyConfirm = false;
|
||||||
if (otaShaStarted) {
|
if (otaShaStarted) {
|
||||||
mbedtls_sha256_free(&otaShaCtx);
|
mbedtls_sha256_free(&otaShaCtx);
|
||||||
otaShaStarted = false;
|
otaShaStarted = false;
|
||||||
|
|
@ -296,7 +298,8 @@ class OtaCharacteristicCallbacks : public NimBLECharacteristicCallbacks {
|
||||||
Serial.printf("OTA: 0xFF received — otaReady=%d, otaEnded=%d, otaConfirmed=%d, otaInProgress=%d\n",
|
Serial.printf("OTA: 0xFF received — otaReady=%d, otaEnded=%d, otaConfirmed=%d, otaInProgress=%d\n",
|
||||||
otaReady, otaEnded, otaConfirmed, otaInProgress);
|
otaReady, otaEnded, otaConfirmed, otaInProgress);
|
||||||
if (!otaEnded) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
Serial.println("OTA: 0xFF confirm accepted, setting otaConfirmed=true");
|
Serial.println("OTA: 0xFF confirm accepted, setting otaConfirmed=true");
|
||||||
|
|
@ -550,6 +553,12 @@ void loop() {
|
||||||
otaReady, otaEnded, otaConfirmed, otaInProgress);
|
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)) {
|
if (otaEnded && !otaConfirmed && (millis() - otaEndedAt > OTA_CONFIRM_TIMEOUT_MS)) {
|
||||||
Serial.printf("OTA: 0xFF confirm timeout (%lu ms) — discarding update, resuming normal operation\n",
|
Serial.printf("OTA: 0xFF confirm timeout (%lu ms) — discarding update, resuming normal operation\n",
|
||||||
millis() - otaEndedAt);
|
millis() - otaEndedAt);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue