Hello together,
currently I'm facing an issue while trying to transfer Firmware.bin from Flutter App to ESP32C3 by BLE for an OTA-Update.
The Firmware has a total size of around 1.1 mb, so I send it in 1024 byte-chunks.
However,
On my Flutter side it is writing the chunk size correctly into characteristic.
flutter: Chunk 1 sent successfully. Total sent: 1024 bytes
flutter: Chunk 2 sent successfully. Total sent: 2048 bytes
flutter: Chunk 3 sent successfully. Total sent: 3072 bytes
flutter: Chunk 4 sent successfully. Total sent: 4096 bytes
and the data on the ESP side are received in correct size, but if I double checked the size which has been saved to SPIFFS, it is always more than it should be? (SPIFFS is formatted before)
This leads to that the SPIFFS size is to low for an 1.1 mb Firmware update...
(Partition scheme is 1.2mb APP / 1.5mb SPIFFS)
Any ideas?
Console:
Received firmware data size: 1024
Chunk number: 1
Chunk saved to file.
Total SPIFFS space: 1318001
Used SPIFFS space: 1506
Free SPIFFS space: 1316495
Waiting for more chunks.
Received firmware data size: 1024
Chunk number: 2
Chunk saved to file.
Total SPIFFS space: 1318001
Used SPIFFS space: 3012
Free SPIFFS space: 1314989
Waiting for more chunks.
Received firmware data size: 1024
Chunk number: 3
Chunk saved to file.
Total SPIFFS space: 1318001
Used SPIFFS space: 4518
Free SPIFFS space: 1313483
Waiting for more chunks.
Received firmware data size: 1024
Chunk number: 4
Chunk saved to file.
class MyFirmwareCharacteristicCallbacks : public BLECharacteristicCallbacks {
public:
void onWrite(BLECharacteristic* pFirmwareUpdateCharacteristic) {
firmwareUpdateInProgress = true;
formatSpiffs();
std::string receivedData = pFirmwareUpdateCharacteristic->getValue();
size_t receivedSize = receivedData.length();
Serial.print("Received firmware data size: ");
Serial.println(receivedSize);
if (receivedSize > 0) {
totalReceivedChunks++;
Serial.print("Chunk number: ");
Serial.println(totalReceivedChunks);
String chunkFileName = "/spiffs/chunk_" + String(totalReceivedChunks) + ".ino.bin";
File chunkFile = SPIFFS.open(chunkFileName, "a");
if (chunkFile) {
chunkFile.write((const uint8_t*)receivedData.c_str(), receivedSize);
chunkFile.close();
Serial.println("Chunk saved to file.");
lastReceivedChunkSize = receivedSize;
printSPIFFSFreeSpace();
} else {
Serial.println("Error opening file for writing.");
Serial.print("Error code (errno): ");
Serial.println(errno);
deepsleep();
}
if (receivedSize < CHUNK_SIZE) {
Serial.println("Last chunk received. Starting firmware update.");
assembleAndFlashFirmware();
} else {
Serial.println("Waiting for more chunks.");
}
} else {
Serial.println("Received firmware data size is zero.");
}
}
};