I am writing an OTA BLE firmware update between flutter Android app and an Espressif ESP32.
Basically, the flutter app sends chunks of data that the firmware expect: the chunk bears the chunkIndex so that the firmware can check nothing is missing since the last reception.
The issue I have is that not all chunks arrive to the firmware, and as it detects that issue, simply breaks the update as expected.
Note that the size of the chunk and its header is of 365 bytes (the MTU I negotiated).
As you can see — in the hope to have better comms — I introduced an extra delay which I'd like to be as short as possible (possibly 0) as I use the withoutResponse: false
. Duration of the write is about 80msecs as per my logs.
A remark I've made is that if I use the withoutResponse: true
, the comm is far better.
Another remark is that other BLE characteristics are actively exchanging information during the transfert process. Is that something that could create issue?
I really need something rock solid. So what am I doing wrong?
for (int i = 0; i < chunksCount; i++) {
final chunk = [
OTA_RX_FB_RECEIVE_DATA_CHUNK,
i >> 8,
i & 0xff,
chunkSize >> 8,
chunkSize & 0xff
];
chunk.addAll(dataChunk);
log("OTA: whole chunk with header: ${chunk.length} bytes");
try {
log("OTA: writing…");
final start = DateTime.now();
await bleFirmwareUpdateTxCharacteristic.write(data
//,withoutResponse: true
);
final d = DateTime.now().difference(start).inMilliseconds;
log("OTA: written in ${d}msecs, now wait a bit");
await Future.delayed(otaBleDelay);
log("OTA: written, done waiting");
} catch (e) {
error("OTA: smartboxFirmwareUpdateBleWrite() error $e");
}```