无线更新演示应用程序 - FreeRTOS
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

无线更新演示应用程序

FreeRTOS 包括一个演示应用程序,用于演示无线 (OTA) 库的功能。OTA 演示应用程序位于freertos/demos/ota/ota_demo_core_mqtt/ota_demo_core_mqtt.c或者freertos/demos/ota/ota_demo_core_http/ota_demo_core_http.c文件。

OTA 演示应用程序执行以下操作:

  1. 初始化 FreeRTOS 网络堆栈和 MQTT 缓冲池。

  2. 使用创建任务来执行 OTA 库vRunOTAUpdateDemo().

  3. 使用 _establishMqttConnection() 创建 MQTT 客户端。

  4. 连接到Amazon IoTMQTT 经纪商使用IotMqtt_Connect()然后注册 MQTT 断开连接回调:prvNetworkDisconnectCallback.

  5. 调用 OTA_AgentInit() 创建 OTA 任务,并注册在 OTA 任务完成时使用的回调。

  6. 重用 MQTT 连接xOTAConnectionCtx.pvControlClient = _mqttConnection;

  7. 如果 MQTT 断开连接,应用程序将暂停 OTA 代理,尝试使用带有抖动的指数延迟重新连接,然后恢复 OTA 代理。

在使用 OTA 更新之前,请完成中的所有先决条件FreeRTOS 无线更新

在完成 OTA 更新的设置后,在支持 OTA 功能的平台上下载、构建、刷写并运行 FreeRTOS OTA 演示。设备特定的演示说明可用于以下 Freertos 认证的设备:

在设备上构建、刷写并运行 OTA 演示应用程序后,您可以使用 Amazon IoT 控制台或 Amazon CLI 来创建 OTA 更新作业。在您创建 OTA 更新任务之后,连接到终端仿真器以查看 OTA 更新的进度。记下此过程中生成的任何错误。

成功 OTA 更新作业会显示类似以下内容的输出。为简便起见,在本示例中,我们删除了列表中的一些行。

249 21207 [iot_thread] [ota_demo_core_mqtt.c:1850] [INFO] [MQTT] Received: 0 Queued: 0 Processed: 0 Dropped: 0 250 21247 [MQTT Agent Task] [core_mqtt.c:886] [INFO] [MQTT] Packet received. ReceivedBytes=601. 251 21247 [MQTT Agent Task] [core_mqtt.c:1045] [INFO] [MQTT] De-serialized incoming PUBLISH packet: DeserializerResult=MQTTSuccess. 252 21248 [MQTT Agent Task] [core_mqtt.c:1058] [INFO] [MQTT] State record updated. New state=MQTTPubAckSend. 253 21249 [MQTT Agent Task] [ota_demo_core_mqtt.c:976] [INFO] [MQTT] Received job message callback, size 548. 254 21252 [OTA Agent Task] [ota.c:1645] [INFO] [OTA] Extracted parameter: [key: value]=[execution.jobId: AFR_OTA-9702f1a3-b747-4c3e-a0eb-a3b0cf83ddbb] 255 21253 [OTA Agent Task] [ota.c:1645] [INFO] [OTA] Extracted parameter: [key: value]=[execution.jobDocument.afr_ota.streamname: AFR_OTA-945d320b-a18b-441b-b435-4a18d4e7671f] 256 21255 [OTA Agent Task] [ota.c:1645] [INFO] [OTA] Extracted parameter: [key: value]=[execution.jobDocument.afr_ota.protocols: ["MQTT"]] 257 21256 [OTA Agent Task] [ota.c:1645] [INFO] [OTA] Extracted parameter: [key: value]=[filepath: aws_demos.bin] 258 21257 [OTA Agent Task] [ota.c:1684] [INFO] [OTA] Extracted parameter: [key: value]=[filesize: 1164016] 259 21258 [OTA Agent Task] [ota.c:1684] [INFO] [OTA] Extracted parameter: [key: value]=[fileid: 0] 260 21259 [OTA Agent Task] [ota.c:1645] [INFO] [OTA] Extracted parameter: [key: value]=[certfile: ecdsa-sha256-signer.crt.pem] 261 21260 [OTA Agent Task] [ota.c:1575] [INFO] [OTA] Extracted parameter [ sig-sha256-ecdsa: MEQCIE1SFkIHHiZAvkPpu6McJtx7SYoD... ] 262 21261 [OTA Agent Task] [ota.c:1684] [INFO] [OTA] Extracted parameter: [key: value]=[fileType: 0] 263 21262 [OTA Agent Task] [ota.c:2199] [INFO] [OTA] Job document was accepted. Attempting to begin the update. 264 21263 [OTA Agent Task] [ota.c:2323] [INFO] [OTA] Job parsing success: OtaJobParseErr_t=OtaJobParseErrNone, Job name=AFR_OTA-9702f1a3-b747-4c3e-a0eb-a3b0cf83ddbb 265 21318 [iot_thread] [ota_demo_core_mqtt.c:1850] [INFO] [MQTT] Received: 0 Queued: 0 Processed: 0 Dropped: 0 266 21418 [iot_thread] [ota_demo_core_mqtt.c:1850] [INFO] [MQTT] Received: 0 Queued: 0 Processed: 0 Dropped: 0 267 21469 [OTA Agent Task] [ota.c:938] [INFO] [OTA] Setting OTA data interface. 268 21470 [OTA Agent Task] [ota.c:2839] [INFO] [OTA] Current State=[CreatingFile], Event=[ReceivedJobDocument], New state=[CreatingFile] 269 21482 [MQTT Agent Task] [core_mqtt.c:886] [INFO] [MQTT] Packet received. ReceivedBytes=3. 270 21483 [OTA Agent Task] [ota_demo_core_mqtt.c:1503] [INFO] [MQTT] SUBSCRIBED to topic $aws/things/__test_infra_thing71/streams/AFR_OTA-945d320b-a18b-441b-b435-4a18d4e7671f/data/cbor to bro 271 21484 [OTA Agent Task] [ota.c:2839] [INFO] [OTA] Current State=[RequestingFileBlock], Event=[CreateFile], New state=[RequestingFileBlock] 272 21518 [iot_thread] [ota_demo_core_mqtt.c:1850] [INFO] [MQTT] Received: 0 Queued: 0 Processed: 0 Dropped: 0 273 21532 [MQTT Agent Task] [core_mqtt_agent_command_functions.c:76] [INFO] [MQTT] Publishing message to $aws/things/__test_infra_thing71/streams/AFR_OTA-945d320b-a18b-441b-b435-4a18d4e7671f/ 274 21534 [OTA Agent Task] [ota_demo_core_mqtt.c:1553] [INFO] [MQTT] Sent PUBLISH packet to broker $aws/things/__test_infra_thing71/streams/AFR_OTA-945d320b-a18b-441b-b435-4a18d4e7671f/get/cbor 275 21534 [OTA Agent Task] [ota_mqtt.c:1112] [INFO] [OTA] Published to MQTT topic to request the next block: topic=$aws/things/__test_infra_thing71/streams/AFR_OTA-945d320b-a18b-441b-b435-4a1 276 21537 [OTA Agent Task] [ota.c:2839] [INFO] [OTA] Current State=[WaitingForFileBlock], Event=[RequestFileBlock], New state=[WaitingForFileBlock] 277 21558 [MQTT Agent Task] [core_mqtt.c:886] [INFO] [MQTT] Packet received. ReceivedBytes=4217. 278 21559 [MQTT Agent Task] [core_mqtt.c:1045] [INFO] [MQTT] De-serialized incoming PUBLISH packet: DeserializerResult=MQTTSuccess. 279 21560 [MQTT Agent Task] [core_mqtt.c:1058] [INFO] [MQTT] State record updated. New state=MQTTPublishDone. 280 21561 [MQTT Agent Task] [ota_demo_core_mqtt.c:1026] [INFO] [MQTT] Received data message callback, size 4120. 281 21563 [OTA Agent Task] [ota.c:2464] [INFO] [OTA] Received valid file block: Block index=0, Size=4096 282 21566 [OTA Agent Task] [ota.c:2683] [INFO] [OTA] Number of blocks remaining: 284 ... // Output removed for brevity 3672 42745 [OTA Agent Task] [ota.c:2464] [INFO] [OTA] Received valid file block: Block index=284, Size=752 3673 42747 [OTA Agent Task] [ota.c:2633] [INFO] [OTA] Received final block of the update. (428298) ota_pal: No such certificate file: ecdsa-sha256-signer.crt.pem. Using certificate in ota_demo_config.h. 3674 42818 [iot_thread] [ota_demo_core_mqtt.c:1850] [INFO] [MQTT] Received: 285 Queued: 285 Processed: 284 Dropped: 0 3675 42918 [iot_thread] [ota_demo_core_mqtt.c:1850] [INFO] [MQTT] Received: 285 Queued: 285 Processed: 284 Dropped: 0 ... // Output removed for brevity 3678 43197 [OTA Agent Task] [ota.c:2654] [INFO] [OTA] Received entire update and validated the signature. 3685 43215 [OTA Agent Task] [ota_demo_core_mqtt.c:862] [INFO] [MQTT] Received OtaJobEventActivate callback from OTA Agent. ... // Output removed for brevity 2 39 [iot_thread] [INFO ][DEMO][390] ---------STARTING DEMO--------- [0;32mI (3633) WIFI: WIFI_EVENT_STA_CONNECTED [0;32mI (4373) WIFI: SYSTEM_EVENT_STA_GOT_IP ... // Output removed for brevity 4 351 [sys_evt] [INFO ][DEMO][3510] Connected to WiFi access point, ip address: 255.255.255.0. 5 351 [iot_thread] [INFO ][DEMO][3510] Successfully initialized the demo. Network type for the demo: 1 6 351 [iot_thread] [ota_demo_core_mqtt.c:1902] [INFO] [MQTT] OTA over MQTT demo, Application version 0.9.1 7 351 [iot_thread] [ota_demo_core_mqtt.c:1323] [INFO] [MQTT] Creating a TLS connection to <endpoint>-ats.iot.us-west-2.amazonaws.com:8883. 9 718 [iot_thread] [core_mqtt.c:886] [INFO] [MQTT] Packet received. ReceivedBytes=2. 10 718 [iot_thread] [core_mqtt_serializer.c:970] [INFO] [MQTT] CONNACK session present bit not set. 11 718 [iot_thread] [core_mqtt_serializer.c:912] [INFO] [MQTT] Connection accepted. ... // Output removed for brevity 17 736 [OTA Agent Task] [ota_demo_core_mqtt.c:1503] [INFO] [MQTT] SUBSCRIBED to topic $aws/things/__test_infra_thing71/jobs/notify-next to broker. 18 737 [OTA Agent Task] [ota_mqtt.c:381] [INFO] [OTA] Subscribed to MQTT topic: $aws/things/__test_infra_thing71/jobs/notify-next 30 818 [iot_thread] [ota_demo_core_mqtt.c:1850] [INFO] [MQTT] Received: 0 Queued: 0 Processed: 0 Dropped: 0 31 819 [OTA Agent Task] [ota.c:1645] [INFO] [OTA] Extracted parameter: [key: value]=[execution.jobId: AFR_OTA-9702f1a3-b747-4c3e-a0eb-a3b0cf83ddbb] 32 820 [OTA Agent Task] [ota.c:1684] [INFO] [OTA] Extracted parameter: [key: value]=[execution.statusDetails.updatedBy: 589824] 33 822 [OTA Agent Task] [ota.c:1645] [INFO] [OTA] Extracted parameter: [key: value]=[execution.jobDocument.afr_ota.streamname: AFR_OTA-945d320b-a18b-441b-b435-4a18d4e7671f] 34 823 [OTA Agent Task] [ota.c:1645] [INFO] [OTA] Extracted parameter: [key: value]=[execution.jobDocument.afr_ota.protocols: ["MQTT"]] 35 824 [OTA Agent Task] [ota.c:1645] [INFO] [OTA] Extracted parameter: [key: value]=[filepath: aws_demos.bin] 36 825 [OTA Agent Task] [ota.c:1684] [INFO] [OTA] Extracted parameter: [key: value]=[filesize: 1164016] 37 826 [OTA Agent Task] [ota.c:1684] [INFO] [OTA] Extracted parameter: [key: value]=[fileid: 0] 38 827 [OTA Agent Task] [ota.c:1645] [INFO] [OTA] Extracted parameter: [key: value]=[certfile: ecdsa-sha256-signer.crt.pem] 39 828 [OTA Agent Task] [ota.c:1575] [INFO] [OTA] Extracted parameter [ sig-sha256-ecdsa: MEQCIE1SFkIHHiZAvkPpu6McJtx7SYoD... ] 40 829 [OTA Agent Task] [ota.c:1684] [INFO] [OTA] Extracted parameter: [key: value]=[fileType: 0] 41 830 [OTA Agent Task] [ota.c:2102] [INFO] [OTA] In self test mode. 42 830 [OTA Agent Task] [ota.c:1936] [INFO] [OTA] New image has a higher version number than the current image: New image version=0.9.1, Previous image version=0.9.0 43 832 [OTA Agent Task] [ota.c:2120] [INFO] [OTA] Image version is valid: Begin testing file: File ID=0 53 896 [OTA Agent Task] [ota.c:794] [INFO] [OTA] Beginning self-test. 62 971 [OTA Agent Task] [ota_demo_core_mqtt.c:1553] [INFO] [MQTT] Sent PUBLISH packet to broker $aws/things/__test_infra_thing71/jobs/AFR_OTA-9702f1a3-b747-4c3e-a0eb-a3b0cf83ddbb/update to br63 971 [MQTT Agent Task] [core_mqtt.c:1045] [INFO] [MQTT] De-serialized incoming PUBLISH packet: DeserializerResult=MQTTSuccess. 65 973 [MQTT Agent Task] [core_mqtt.c:1058] [INFO] [MQTT] State record updated. New state=MQTTPublishDone. 64 973 [OTA Agent Task] [ota_demo_core_mqtt.c:902] [INFO] [MQTT] Successfully updated with the new image.