OTA(Over-the-Air) 업데이트 데모 애플리케이션 - 무료 RTOS

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

OTA(Over-the-Air) 업데이트 데모 애플리케이션

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. vRunOTAUpdateDemo()를 사용하여 OTA 라이브러리 연습을 위한 태스크를 생성합니다.

  3. _establishMqttConnection()를 사용하여 MQTT 클라이언트를 생성합니다.

  4. IotMqtt_Connect()를 사용하여 AWS IoT MQTT 브로커에 연결하고 MQTT 연결 해제 콜백 prvNetworkDisconnectCallback을 등록합니다.

  5. OTA_AgentInit()를 호출하여 OTA 작업을 생성하고, OTA 작업이 완료될 때 사용할 콜백을 등록합니다.

  6. xOTAConnectionCtx.pvControlClient = _mqttConnection;을 사용하여 MQTT 연결을 재사용합니다.

  7. MQTT 연결이 끊어지면 애플리케이션은 OTA 에이전트를 일시 중단하고 지수 지연 및 지터를 사용하여 재연결을 시도한 다음 OTA 에이전트를 다시 시작합니다.

OTA 업데이트를 사용하려면 먼저 FreeRTOS 무선 업데이트(OTA)에 명시된 모든 사전 조건을 완료해야 합니다.

OTA 업데이트를 위한 설정을 완료한 경우 OTA 기능을 지원하는 플랫폼에서 FreeRTOS OTA 데모를 다운로드, 빌드, 플래시 및 실행합니다. 디바이스별 데모 지침은 다음 FreeRTOS 적격 디바이스에서 사용할 수 있습니다.

디바이스에서 OTA 데모 애플리케이션을 빌드, 플래시 및 실행한 후에는 AWS IoT 콘솔 또는 AWS 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.