This class can make it possible for you to update the firmware of your ESP32 over the air by downloading the firmware using a SIM800(C) modem.
If the download of a chunk fails due to a loss of connection, the download of that specific chunk will be restarted, after testing, this was the best way to ensure file integrity (compare to resuming to the last written byte).
Patience is needed as the whole update process can take up to 20 minutes for a file of 1MB.
Here is a quick example on how to use the class:
void performFirmwareUpdate() {
// Initialize the FOTA updater
fotaUpdater.init(serverAddress, 443, downloadPath, fileSize, & SerialSIM800C, & FileSystem);
// Adjust chunk size
fotaUpdater.chunkSize = 25000;
// Set progress callback
fotaUpdater.onDownloadFirmwareProgress(onUpdateProgress);
// Download firmware
if (fotaUpdater.download(firmwareFile)) { // firmwareFile is the name of the file you want to write to memory
// Verify MD5 hash
if (fotaUpdater.verifyMD5(firmwareFile, knownMD5)) {
// Perform the update
if (fotaUpdater.performUpdate(firmwareFile)) {
Serial.println("Flashed successfully!");
// Reset ESP32 to boot on new firmware
}
}
}
}
Verifying the MD5 checksum is optional but strongly recommended to avoid writing corrupted data to the ESP32.
You can also download the firmware as a gzip file to be expanded before calling performUpdate using the ESP32-targz library.