Device disconnects at 1.2-1.3%
Hello, I've been playing with both of your ESP32 OTA repos, and with either one, the device will disconnect very early in the file transfer. I did get it to complete by reconnecting and trying again just twice, once failing with a checksum error, and the other time failing with OTA end failure.
These are the logs on the iOS side from a typical attempt (I added error logging to didDisconnect):
2025-05-01 06:16:41 +0000 FUNC SendFile
file transfer: 0.05275652862041236%
file transfer: 0.10551305724083582%
file transfer: 0.15826958586124817%
file transfer: 0.21102611448167163%
file transfer: 0.263782643102084%
file transfer: 0.31653917172249635%
file transfer: 0.3692957003429198%
file transfer: 0.42205222896333217%
file transfer: 0.4748087575837556%
file transfer: 0.527565286204168%
file transfer: 0.5803218148245803%
file transfer: 0.6330783434450038%
file transfer: 0.6858348720654162%
file transfer: 0.7385914006858396%
file transfer: 0.791347929306252%
file transfer: 0.8441044579266643%
file transfer: 0.8968609865470878%
file transfer: 0.9496175151675001%
file transfer: 1.0023740437879236%
file transfer: 1.055130572408336%
file transfer: 1.1078871010287483%
file transfer: 1.1606436296491718%
file transfer: 1.2134001582695841%
file transfer: 1.2661566868900076%
file transfer: 1.31891321551042%
file transfer: 1.3716697441308323%
2025-05-01 06:16:43 +0000 CM DidDisconnectPeripheral
2025-05-01 06:16:43 +0000 ESP32 iOS OTA disconnected
2025-05-01 06:16:43 +0000 Error: The connection has timed out unexpectedly.
2025-05-01 06:16:43 +0000 connect: try reconnect when back in range
And over on the Arduino side:
23:16:36.792 -> start advertising
23:16:36.991 -> *** App connected
23:16:36.991 -> main loop started
23:16:41.706 -> BeginOTA
23:16:41.706 -> Running partition type 0 subtype 16 (offset 0x00010000) Writing to partition subtype 17 at offset 0x150000*** App disconnected
If you have any insight, I'd appreciate it! I'm not using NimBLE in already well-established my project, so I've been focusing on this repo. Thanks!
This is because calls to esp_ota_begin take up to 6 seconds, and in that time, BLE cannot update. This causes the device to disconnect. The solution to this is to call esp_ota_begin before BLEDevice::init() so the device is ready to update. Of course, you don't want your device to constantly ready to update, so you can have a separate characteristic that manages the mode of the device and have it reboot into OTA mode when that characteristic is set.