We're using AWS IoT Device SDK for Embedded C (Espressif ESP32 port) to connect our ESP32 device to AWS. I'm working on OTA using the ota-for-aws-iot-embedded-sdk library included in the SDK.
We're creating AWS IoT Jobs for the updates, and sending the firmware image via MQTT.
The basics are working (download and install new firmware).
What I need to do is verify the version of the new firmware BEFORE downloading and installing it. The AWS library doesn't seem to have any system to do this (unless I missed something)! At the moment, if the "new" firmware is actually the same or older, the library will download it, write to flash, install and reboot, THEN check the version, and will then have to roll back. This is unsatisfactory. Note that we DO send the current version to the cloud via Device Shadow, but we also allow updates via BLE so I'd really like to check the incoming version to make sure it's not out of date already.
Here's what I have:
- I've put the version number into the "fileName" field of the job doc, since we don't need "fileName" for anything else.
- When a new OTA job arrives on the device, I handle the application callback from the OTA lib, for the "OtaJobEventReceivedJob" event.
- In this event, I check the version numbers from the field in the job doc. OK so far.
- Now I want to reject the update if it's out of date. Reject means:
- Don't download
- Send a message to the cloud to reject the job so it doesn't keep getting resent
- Clear any state in the OTA lib
I have tried this:
OTA_SetImageState(OtaImageStateAborted);
It sort-of works, but the abort event gets put on the queue, so the device starts erasing the OTA update partition, and doesn't reject the OTA job until that has finished.
Is there a better method to check the new firmware version before download? A better way to tell the OTA library to reject a job without starting it?