Home

Awesome

FreeRTOS Labs - OTA Example for AWS IoT Core

AWS IoT CoreOTA enables simple Over-The-Air (OTA) updates through an extensible and modular set of interfaces. When properly setup, the CoreOTA 'Orchestrator' (see CoreOTA concepts & architecture) will handle the standard OTA behaviors like downloading the OTA file, parsing update metadata, and updating OTA status remotely. These functions are performed through the different interfaces which allow for customization for new fields and extensibility to new services. Using this library will allow you to easily configure OTA updates from a variety of sources and keep OTA functionality separated from any on-device application.

This repository contains the following two example OTA orchestrators. Both orchestrators use FreeRTOS, coreMQTT and IoT Jobs library.

  1. Simple OTA Orchestrator: It is a simple orchestrator which checks IoT Core for an existing OTA Job, download its associated file, output the file over the command line, and report success back to IoT Core.
  2. OTA Agent Orchestrator: This orchestrator is designed to mimic the OTA agent found in the old OTA repository. The OTA agent orchestrator operates by managing a state machine that tracks the current status of the download process. The state machine is influenced by receiving events that are sourced by either internal calls or the main application. The OTA agent requires a loop to be running to receive and process these incoming events before it can start.

0. Concepts and Architecture

A detailed breakdown of important concepts and architectural decisions can be found here.

1. Demo Prerequisites

2. Demo Setup

2.1 Setup AWS IoT Core

To setup AWS IoT Core, follow the AWS IoT Core Setup Guide. The guide shows you how to sign up for an AWS account, create a user, and register your device with AWS IoT Core. After you have followed the instructions in the AWS IoT Core Setup Guide, you will have acquired the following items:

The root CA certificate can also be downloaded here. The simulator must be provided with these entities in order for it to connect with AWS IoT Core.

2.2 Perform one-time setup of OTA cloud resources

Before you create an OTA job, the following resources are required. This is a one time setup required for performing OTA firmware updates. Make a note of the names of the resources you create, as you will need to provide them during subsequent configuration steps.

2.3 Build the coreOTA_Demo Binary

On your personal computer, open a terminal and issue the following commands:

# optional command - skip if you do not have Nix installed
nix develop --extra-experimental-features "nix-command flakes"
mkdir build
cd build
cmake ..

To build Simple OTA Orchestrator Demo

make coreOTA_Demo

To build OTA Agent Orchestrator Demo

make coreOTA_Agent_Demo

3. Run the OTA Demo

3.1 Create an OTA Update in AWS IoT Core

Follow the steps to Create an OTA Update with the AWS IoT Core Console. Apply the following options:

3.2 Run the simulator

After you've created your OTA update, start the simulator by using the following command in your build/ directory:

To run Simple OTA Orchestrator Demo

./coreOTA_Demo {certificateFilePath} {privateKeyFilePath} {rootCAFilePath} {endpoint} {thingName}

To run OTA Agent Orchestrator Demo

./coreOTA_Agent_Demo {certificateFilePath} {privateKeyFilePath} {rootCAFilePath} {endpoint} {thingName}

3.3 Verify successful OTA in the AWS IoT Core Console

After the simulator stops printing output, check the IoT Core Console to verify that the OTA Job you created is marked as "Successful".

4. Run the Unit Tests

4.1 Running the OTA Parser Unit tests

The unit tests are broken out by the 'module' they reside in (aka the /lib folder) and can be executed per module. To run the OTA parser unit tests you'll run the following commands

From here you can build the unit tests...

cd lib/iot-core-jobs-ota-parser
cmake -B build -S test
make -C build

Once built, the test executables can be found under the lib/iot-core-jobs-ota-parser/build/bin/tests/ directory

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT License.