Skip to content

Commit

Permalink
Adding OTA agent demo to the build system (#41)
Browse files Browse the repository at this point in the history
* Rearranging the ota demo files.

* Adding support to build OTA-agent demo.

* Updating OTA-Agent demo according to update MQTT stream library.

* Updating README file

* Updating README with some more information about OTA agent orchestrator.

---------

Co-authored-by: Manvendra Sharma <[email protected]>
  • Loading branch information
manvensh and manvensh-eero authored Oct 18, 2023
1 parent f70e803 commit be7aba4
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 15 deletions.
40 changes: 37 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ target_include_directories(iot-core-mqtt-file-downloader

add_executable(
coreOTA_Demo
./demo/main.c
./demo/ota_demo.c
./demo/ota/main.c
./demo/ota/ota_demo.c
./demo/transport/openssl_posix.c
./demo/transport/sockets_posix.c
./demo/transport/transport_wrapper.c
Expand All @@ -137,7 +137,7 @@ add_executable(

target_include_directories(
coreOTA_Demo
PUBLIC "${CMAKE_CURRENT_LIST_DIR}/source" "${CMAKE_CURRENT_LIST_DIR}/demo"
PUBLIC "${CMAKE_CURRENT_LIST_DIR}/source" "${CMAKE_CURRENT_LIST_DIR}/demo/"
"${CMAKE_CURRENT_LIST_DIR}/cfg")

target_link_libraries(
Expand All @@ -157,3 +157,37 @@ find_library(LIBRT rt)
if(LIBRT)
target_link_libraries(coreOTA_Demo PRIVATE rt)
endif()

add_executable(
coreOTA_Agent_Demo
./demo/ota-agent/main.c
./demo/ota-agent/ota_demo.c
./demo/os/ota_os_freertos.c
./demo/transport/openssl_posix.c
./demo/transport/sockets_posix.c
./demo/transport/transport_wrapper.c
./demo/utils/clock_posix.c
./demo/utils/freertos_hooks.c)

target_include_directories(
coreOTA_Agent_Demo
PUBLIC "${CMAKE_CURRENT_LIST_DIR}/source" "${CMAKE_CURRENT_LIST_DIR}/demo/"
"${CMAKE_CURRENT_LIST_DIR}/cfg")

target_link_libraries(
coreOTA_Agent_Demo
PRIVATE coreMQTT
mqtt_wrapper
OpenSSL::SSL
coreJSON
tinycbor
backoffAlgorithm
freertos_kernel
iot-core-jobs
iot-core-jobs-ota-parser
iot-core-mqtt-file-downloader)

find_library(LIBRT rt)
if(LIBRT)
target_link_libraries(coreOTA_Agent_Demo PRIVATE rt)
endif()
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ 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 an example of an OTA orchestrator using FreeRTOS and
coreMQTT. The example will check 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.
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

Expand Down Expand Up @@ -91,7 +99,18 @@ nix develop --extra-experimental-features "nix-command flakes"
mkdir build
cd build
cmake ..
make
```

**To build Simple OTA Orchestrator Demo**

```bash
make coreOTA_Demo
```

**To build OTA Agent Orchestrator Demo**

```bash
make coreOTA_Agent_Demo
```

## 3. Run the OTA Demo
Expand All @@ -114,10 +133,16 @@ Apply the following options:
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
Expand Down
2 changes: 1 addition & 1 deletion demo/os/ota_os_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/* OTA OS POSIX Interface Includes.*/

#include "ota_demo.h"
#include "ota-agent/ota_demo.h"
#include "ota_os_freertos.h"

/* OTA Event queue attributes.*/
Expand Down
29 changes: 23 additions & 6 deletions demo/ota-agent/ota_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "mqtt_wrapper.h"
#include "ota_demo.h"
#include "ota_job_processor.h"
#include "ota_os_freertos.h"
#include "os/ota_os_freertos.h"
#include "FreeRTOS.h"
#include "semphr.h"

Expand Down Expand Up @@ -58,6 +58,8 @@ static void freeOtaDataEventBuffer( OtaDataEvent_t * const buffer );

static void handleMqttStreamsBlockArrived( uint8_t *data, size_t dataLength );

static void requestDataBlock( void );


static void freeOtaDataEventBuffer( OtaDataEvent_t * const pxBuffer )
{
Expand Down Expand Up @@ -202,6 +204,25 @@ static bool receivedJobDocumentHandler( OtaJobEventData_t * jobDoc )
return handled;
}

static void requestDataBlock( void )
{
char getStreamRequest[ GET_STREAM_REQUEST_BUFFER_SIZE ];
size_t getStreamRequestLength = 0U;

getStreamRequestLength = mqttDownloader_createGetDataBlockRequest( mqttFileDownloaderContext.dataType,
currentFileId,
mqttFileDownloader_CONFIG_BLOCK_SIZE,
currentBlockOffset,
NUM_OF_BLOCKS_REQUESTED,
getStreamRequest );

mqttWrapper_publish( mqttFileDownloaderContext.topicGetStream,
mqttFileDownloaderContext.topicGetStreamLength,
( uint8_t * ) getStreamRequest,
getStreamRequestLength );
}


static void processOTAEvents() {
OtaEventMsg_t recvEvent = { 0 };
OtaEvent_t recvEventId = 0;
Expand Down Expand Up @@ -244,11 +265,7 @@ static void processOTAEvents() {
otaAgentState = OtaAgentStateRequestingFileBlock;
printf("Request File Block event Received \n");
printf("-----------------------------------\n");
mqttDownloader_requestDataBlock( &mqttFileDownloaderContext,
currentFileId,
mqttFileDownloader_CONFIG_BLOCK_SIZE,
currentBlockOffset,
NUM_OF_BLOCKS_REQUESTED );
requestDataBlock();
break;
case OtaAgentEventReceivedFileBlock:
printf("Received File Block event Received \n");
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit be7aba4

Please sign in to comment.