0

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.

See here for 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?

Jeremy
  • 1,083
  • 3
  • 13
  • 25
  • If you hook your code somewhere in this function: https://github.com/aws/ota-for-aws-iot-embedded-sdk/blob/main/source/ota.c#L2345 would that work? – brushtakopo Mar 20 '23 at 14:47
  • @brushtakopo That's an option, but I'm trying to avoid hacking the library code! – Jeremy Mar 20 '23 at 18:17
  • I do believe that your approach is correct. But the state you set, is put back at the end of the queue, which I think is wrong. You can also create a PR in github. Maybe the team will have a better flow or a fix. In my case, I'd modified the library to return a value for the callOtaCallback: https://github.com/aws/ota-for-aws-iot-embedded-sdk/blob/main/source/ota.c#L2402 based on this return value, stop the OTA directly, don't proceed further. – brushtakopo Mar 21 '23 at 16:03

0 Answers0