OTA server: chunk 0 geen ACK na 3 pogingen #1

Closed
opened 2026-08-01 03:13:34 +02:00 by eddy · 2 comments
Owner

Symptoom

Server ESP gaat in OTA-modus (led knippert groen) maar chunk 0 krijgt nooit een ACK terug.

Logs (Android)

D/OtaManager: Sent chunk 0/2277 (241 bytes) attempt 1
D/OtaManager: Sent chunk 0/2277 (241 bytes) attempt 2
D/OtaManager: Sent chunk 0/2277 (241 bytes) attempt 3
E/OtaManager: OTA mislukt: chunk 0 geen ACK na 3 pogingen

Tussenoplossingen al toegepast (geen oplossing)

  • enableOtaNotifications(): expliciete CCCD descriptor write voor Android 13+
  • 300ms delay tussen CCCD write en OTA start
  • OTA_CMD_START: retry tot 3x
  • Firmware binary: correct server-path ipv stale root firmware.bin

Mogelijke oorzaken

  • Samsung BLE stack writeCharacteristic prior command not finished blocking GATT queue
  • ESP esp_ota_write op OPI flash te traag voor 2s timeout
  • NimBLE notify() silently failing

Workaround

OTA via USB werkt wel (EspFlasher)

## Symptoom Server ESP gaat in OTA-modus (led knippert groen) maar chunk 0 krijgt nooit een ACK terug. ## Logs (Android) ``` D/OtaManager: Sent chunk 0/2277 (241 bytes) attempt 1 D/OtaManager: Sent chunk 0/2277 (241 bytes) attempt 2 D/OtaManager: Sent chunk 0/2277 (241 bytes) attempt 3 E/OtaManager: OTA mislukt: chunk 0 geen ACK na 3 pogingen ``` ## Tussenoplossingen al toegepast (geen oplossing) - `enableOtaNotifications()`: expliciete CCCD descriptor write voor Android 13+ - 300ms delay tussen CCCD write en OTA start - OTA_CMD_START: retry tot 3x - Firmware binary: correct server-path ipv stale root `firmware.bin` ## Mogelijke oorzaken - Samsung BLE stack writeCharacteristic prior command not finished blocking GATT queue - ESP esp_ota_write op OPI flash te traag voor 2s timeout - NimBLE notify() silently failing ## Workaround OTA via USB werkt wel (EspFlasher)
eddy added reference main 2026-08-01 03:31:08 +02:00
eddy self-assigned this 2026-08-01 21:44:53 +02:00
Author
Owner

Root Cause

De sendOtaNotify() + delay(100) wait-loop stond in de NimBLE onWrite callback, die in de BLE task context draait. De delay() blokkeerde de BLE task waardoor de GATT notificatie (OTA_STATUS_COMPLETE) nooit verzonden werd. Android kreeg de notificatie nooit → timeout → foutmelding "OTA mislukt: ESP SHA256 verificatie fout". De firmware was wel correct geflashed (SHA256 OK), maar de handshake faalde.

Fixes

ESP (src/main.cpp)

  1. Wait-loop verplaatst van onWrite naar loop() — BLE task blijft vrij om de notificatie te verzenden
  2. esp_ota_set_boot_partition() verplaatst naar ná Android-bevestiging (0xFF), zodat oude firmware actief blijft tot de handshake slaagt
  3. Twee-weg handshake: ESP stuurt OTA_STATUS_COMPLETE → wacht in loop() op 0xFF confirmatie → switch boot partition + reboot

Android (OtaManager.kt)

  • Stuurt 0xFF bevestigingsbyte na ontvangst finalStatus = 0x10

Testresultaat

OTA v12→v13 getest op Samsung A26: alle 2278 chunks succesvol, SHA256 verificatie OK, handshake voltooid, ESP reboot correct naar v13. Geen foutmeldingen.

## Root Cause De `sendOtaNotify()` + `delay(100)` wait-loop stond in de NimBLE `onWrite` callback, die in de BLE task context draait. De `delay()` blokkeerde de BLE task waardoor de GATT notificatie (`OTA_STATUS_COMPLETE`) nooit verzonden werd. Android kreeg de notificatie nooit → timeout → foutmelding "OTA mislukt: ESP SHA256 verificatie fout". De firmware was wel correct geflashed (SHA256 OK), maar de handshake faalde. ## Fixes ### ESP (`src/main.cpp`) 1. Wait-loop verplaatst van `onWrite` naar `loop()` — BLE task blijft vrij om de notificatie te verzenden 2. `esp_ota_set_boot_partition()` verplaatst naar ná Android-bevestiging (0xFF), zodat oude firmware actief blijft tot de handshake slaagt 3. Twee-weg handshake: ESP stuurt `OTA_STATUS_COMPLETE` → wacht in `loop()` op 0xFF confirmatie → switch boot partition + reboot ### Android (`OtaManager.kt`) - Stuurt 0xFF bevestigingsbyte na ontvangst `finalStatus = 0x10` ## Testresultaat OTA v12→v13 getest op Samsung A26: alle 2278 chunks succesvol, SHA256 verificatie OK, handshake voltooid, ESP reboot correct naar v13. Geen foutmeldingen.
Author
Owner

wijzigingen nooit gecommit en daardoor verloren gegaan
issue is weer helemaal open

wijzigingen nooit gecommit en daardoor verloren gegaan issue is weer helemaal open
eddy closed this issue 2026-08-02 00:49:12 +02:00
Sign in to join this conversation.
No description provided.