Amazon FreeRTOS
User Guide

OTA Demo Application

Amazon FreeRTOS includes a demo application that demonstrates the use of the OTA library. The OTA demo application is located in the demos\common\ota subdirectory.

Before you create an OTA update, read Amazon FreeRTOS Over-the-Air Updates and complete all prerequisites listed there.

The OTA demo application:

  1. Initializes the FreeRTOS network stack and MQTT buffer pool. (See main.c.)

  2. Creates a task to exercise the OTA library. (See vOTAUpdateDemoTask in aws_ota_update_demo.c.)

  3. Creates an MQTT client using MQTT_AGENT_Create.

  4. Connects to the AWS IoT MQTT broker using MQTT_AGENT_Connect.

  5. Calls OTA_AgentInit to create the OTA task and registers a callback to be used when the OTA task is complete.

You can use the AWS IoT console or the AWS CLI to create an OTA update job. After you have created an OTA update job, connect a terminal emulator to see the progress of the OTA update. Make a note of any errors generated during the process.

A successful OTA update job displays output like the following. Some lines in this example have been removed from the listing for brevity.

313 267848 [OTA] [OTA] Queued: 1 Processed: 1 Dropped: 0 314 268733 [OTA Task] [OTA] Set job doc parameter [ jobId: fe18c7ec_8c31_4438_b0b9_ad55acd95610 ] 315 268734 [OTA Task] [OTA] Set job doc parameter [ streamname: 327 ] 316 268734 [OTA Task] [OTA] Set job doc parameter [ filepath: /sys/mcuflashimg.bin ] 317 268734 [OTA Task] [OTA] Set job doc parameter [ filesize: 130388 ] 318 268735 [OTA Task] [OTA] Set job doc parameter [ fileid: 126 ] 319 268735 [OTA Task] [OTA] Set job doc parameter [ attr: 0 ] 320 268735 [OTA Task] [OTA] Set job doc parameter [ certfile: tisigner.crt.der ] 321 268737 [OTA Task] [OTA] Set job doc parameter [ sig-sha1-rsa: Q56qxHRq3Lxv6KkorvilVs4AyGJbWsJd ] 322 268737 [OTA Task] [OTA] Job was accepted. Attempting to start transfer. 323 268737 [OTA Task] Sending command to MQTT task. 324 268737 [MQTT] Received message 50000 from queue. 325 268848 [OTA] [OTA] Queued: 2 Processed: 1 Dropped: 0 326 269039 [MQTT] MQTT Subscribe was accepted. Subscribed. 327 269039 [MQTT] Notifying task. 328 269040 [OTA Task] Command sent to MQTT task passed. 329 269041 [OTA Task] [OTA] Subscribed to topic: $aws/things/TI-LaunchPad/streams/327 330 269848 [OTA] [OTA] Queued: 2 Processed: 1 Dropped: 0 ... // Output removed for brevity 346 284909 [OTA Task] [OTA] file token: 74594452 .. // Output removed for brevity 363 301327 [OTA Task] [OTA] file ready for access. 364 301327 [OTA Task] [OTA] Returned buffer to MQTT Client. 365 301328 [OTA Task] Sending command to MQTT task. 366 301328 [MQTT] Received message 60000 from queue. 367 301328 [MQTT] Notifying task. 368 301329 [OTA Task] Command sent to MQTT task passed. 369 301329 [OTA Task] [OTA] Published file request to $aws/bin/things/TI-LaunchPad/streams/327/get 370 301632 [OTA Task] [OTA] Received file block 0, size 1024 371 301647 [OTA Task] [OTA] Remaining: 127 ... // Output removed for brevity 508 304622 [OTA Task] Sending command to MQTT task. 509 304622 [MQTT] Received message 70000 from queue. 510 304622 [MQTT] Notifying task. 511 304623 [OTA Task] Command sent to MQTT task passed. 512 304623 [OTA Task] [OTA] Published file request to $aws/bin/things/TI-LaunchPad/streams/327/get 513 304860 [OTA] [OTA] Queued: 47 Processed: 47 Dropped: 83 514 304926 [OTA Task] [OTA] Received file block 4, size 1024 515 304941 [OTA Task] [OTA] Remaining: 82 ... // Output removed for brevity 797 315047 [MQTT] MQTT Publish was successful. 798 315048 [MQTT] Notifying task. 799 315048 [OTA Task] Command sent to MQTT task passed. 800 315049 [OTA Task] [OTA] Published 'IN_PROGRESS' status to $aws/things/TI-LaunchPad/jobs/fe18c7ec_8c31_4438_b0b9_ad55acd9561801 315049 [OTA Task] Sending command to MQTT task. 802 315049 [MQTT] Received message d0000 from queue. 803 315150 [MQTT] MQTT Unsubscribe was successful. 804 315150 [MQTT] Notifying task. 805 315151 [OTA Task] Command sent to MQTT task passed. 806 315152 [OTA Task] [OTA] Un-subscribed from topic: $aws/things/TI-LaunchPad/streams/327 807 315172 [OTA Task] Sending command to MQTT task. 808 315172 [MQTT] Received message e0000 from queue. 809 315273 [MQTT] MQTT Unsubscribe was successful. 810 315273 [MQTT] Notifying task. 811 315274 [OTA Task] Command sent to MQTT task passed. 812 315274 [OTA Task] [OTA] Un-subscribed from topic: $aws/things/TI-LaunchPad/streams/327 813 315275 [OTA Task] [OTA] Resetting MCU to activate new image. 0 0 [Tmr Svc] Starting Wi-Fi Module ... 1 0 [Tmr Svc] Simple Link task created Device came up in Station mode 2 137 [Tmr Svc] Wi-Fi module initialized. 3 137 [Tmr Svc] Starting key provisioning... 4 137 [Tmr Svc] Write root certificate... 5 243 [Tmr Svc] Write device private key... 6 339 [Tmr Svc] Write device certificate... 7 436 [Tmr Svc] Key provisioning done... Device disconnected from the AP on an ERROR..!! [WLAN EVENT] STA Connected to the AP: Guest , BSSID: 44:48:c1:ba:b2:c3 [NETAPP EVENT] IP acquired by the device Device has connected to Guest Device IP Address is 192.168.3.72 8 1443 [Tmr Svc] Wi-Fi connected to AP Guest. 9 1444 [Tmr Svc] IP Address acquired 192.168.3.72 10 1444 [OTA] OTA demo version 0.9.1 11 1445 [OTA] Creating MQTT Client... 12 1445 [OTA] Connecting to broker... 13 1445 [OTA] Sending command to MQTT task. 14 1445 [MQTT] Received message 10000 from queue. 15 2910 [MQTT] MQTT Connect was accepted. Connection established. 16 2910 [MQTT] Notifying task. 17 2911 [OTA] Command sent to MQTT task passed. 18 2912 [OTA] Connected to broker. 19 2913 [OTA Task] Sending command to MQTT task. 20 2913 [MQTT] Received message 20000 from queue. 21 3014 [MQTT] MQTT Subscribe was accepted. Subscribed. 22 3014 [MQTT] Notifying task. 23 3015 [OTA Task] Command sent to MQTT task passed. 24 3015 [OTA Task] [OTA] Subscribed to topic: $aws/things/TI-LaunchPad/jobs/$next/get/accepted 25 3028 [OTA Task] Sending command to MQTT task. 26 3028 [MQTT] Received message 30000 from queue. 27 3129 [MQTT] MQTT Subscribe was accepted. Subscribed. 28 3129 [MQTT] Notifying task. 29 3130 [OTA Task] Command sent to MQTT task passed. 30 3138 [OTA Task] [OTA] Subscribed to topic: $aws/things/TI-LaunchPad/jobs/notify-next 31 3138 [OTA Task] [OTA] Check For Update #0 32 3138 [OTA Task] Sending command to MQTT task. 33 3138 [MQTT] Received message 40000 from queue. 34 3241 [MQTT] MQTT Publish was successful. 35 3241 [MQTT] Notifying task. 36 3243 [OTA Task] Command sent to MQTT task passed. 37 3245 [OTA Task] [OTA] Set job doc parameter [ clientToken: 0:TI-LaunchPad ] 38 3245 [OTA Task] [OTA] Set job doc parameter [ jobId: fe18c7ec_8c31_4438_b0b9_ad55acd95610 ] 39 3245 [OTA Task] [OTA] Identified job doc parameter [ self_test ] 40 3246 [OTA Task] [OTA] Set job doc parameter [ updatedBy: 589827 ] 41 3246 [OTA Task] [OTA] Set job doc parameter [ streamname: 327 ] 42 3246 [OTA Task] [OTA] Set job doc parameter [ filepath: /sys/mcuflashimg.bin ] 43 3247 [OTA Task] [OTA] Set job doc parameter [ filesize: 130388 ] 44 3247 [OTA Task] [OTA] Set job doc parameter [ fileid: 126 ] 45 3247 [OTA Task] [OTA] Set job doc parameter [ attr: 0 ] 46 3247 [OTA Task] [OTA] Set job doc parameter [ certfile: tisigner.crt.der ] 47 3249 [OTA Task] [OTA] Set job doc parameter [ sig-sha1-rsa: Q56qxHRq3Lxv6KkorvilVs4AyGJbWsJd ] 48 3249 [OTA Task] [OTA] Job is ready for self test. 49 3250 [OTA Task] Sending command to MQTT task. 51 3351 [MQTT] MQTT Publish was successful. 52 3352 [MQTT] Notifying task. 53 3352 [OTA Task] Command sent to MQTT task passed. 54 3353 [OTA Task] [OTA] Published 'IN_PROGRESS' status to $aws/things/TI-LaunchPad/jobs/fe18c7ec_8c31_4438_b0b9_ad55acd95610/u55 3353 [OTA Task] Sending command to MQTT task. 56 3353 [MQTT] Received message 60000 from queue. 57 3455 [MQTT] MQTT Unsubscribe was successful. 58 3455 [MQTT] Notifying task. 59 3456 [OTA Task] Command sent to MQTT task passed. 60 3456 [OTA Task] [OTA] Un-subscribed from topic: $aws/things/TI-LaunchPad/streams/327 61 3456 [OTA Task] [OTA] Accepted final image. Commit. 62 3578 [OTA Task] Sending command to MQTT task. 63 3578 [MQTT] Received message 70000 from queue. 64 3779 [MQTT] MQTT Publish was successful. 65 3780 [MQTT] Notifying task. 66 3780 [OTA Task] Command sent to MQTT task passed. 67 3781 [OTA Task] [OTA] Published 'SUCCEEDED' status to $aws/things/TI-LaunchPad/jobs/fe18c7ec_8c31_4438_b0b9_ad55acd95610/upd68 3781 [OTA Task] [OTA] Returned buffer to MQTT Client. 69 4251 [OTA] [OTA] Queued: 1 Processed: 1 Dropped: 0 70 4381 [OTA Task] [OTA] Missing job parameter: execution 71 4382 [OTA Task] [OTA] Missing job parameter: jobId 72 4382 [OTA Task] [OTA] Missing job parameter: jobDocument 73 4382 [OTA Task] [OTA] Missing job parameter: ts_ota 74 4382 [OTA Task] [OTA] Missing job parameter: files 75 4382 [OTA Task] [OTA] Missing job parameter: streamname 76 4382 [OTA Task] [OTA] Missing job parameter: certfile 77 4382 [OTA Task] [OTA] Missing job parameter: filepath 78 4383 [OTA Task] [OTA] Missing job parameter: filesize 79 4383 [OTA Task] [OTA] Missing job parameter: sig-sha1-rsa 80 4383 [OTA Task] [OTA] Missing job parameter: fileid 81 4383 [OTA Task] [OTA] Missing job parameter: attr 82 4383 [OTA Task] [OTA] Returned buffer to MQTT Client. 83 5251 [OTA] [OTA] Queued: 2 Processed: 2 Dropped: 0