本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 MQTT 進行 OTA 更新的先決條件
重要
這是 FreeRTOS 使用者指南的封存版本,可與 FreeRTOS 版本 202012.00 搭配使用。如需本文件的最新版本,請參閱 FreeRTOS 使用者指南。
本節描述使用 MQTT 執行無線 (OTA) 更新的一般需求。
若要提供存取權,請新增權限至您的使用者、群組或角色:
-
中的使用者和群組 AWS IAM Identity Center:
建立權限合集。請按照 AWS IAM Identity Center 使用者指南 中的 建立權限合集 說明進行操作。
-
透過身分提供者在 IAM 中管理的使用者:
建立聯合身分的角色。遵循「IAM 使用者指南」的為第三方身分提供者 (聯合) 建立角色中的指示。
-
IAM 使用者:
-
建立您的使用者可擔任的角色。請按照「IAM 使用者指南」的為 IAM 使用者建立角色中的指示。
-
(不建議) 將政策直接附加至使用者,或將使用者新增至使用者群組。請遵循 IAM 使用者指南的新增許可到使用者 (主控台) 中的指示。
-
最低需求
-
裝置韌體必須包含必要的 FreeRTOS 程式庫 (coreMQTT、OTA 代理程式及其相依性)。
-
需要 FreeRTOS 1.4.0 版或更新版本。不過,我們建議您儘可能使用最新版本。
組態
從 201912.00 版開始,FreeRTOS OTA 可以使用 HTTP 或 MQTT 通訊協定,將韌體更新映像從 傳輸 AWS IoT 到 裝置。如果您在 FreeRTOS 中建立 OTA 更新時指定這兩個通訊協定,則每個裝置都會決定用於傳輸映像的通訊協定。如需詳細資訊,請參閱使用 HTTP 進行 OTA 更新的先決條件。
根據預設,aws_ota_agent_config.h
中的 OTA 通訊協定組態會使用 MQTT 通訊協定:
/** * @brief The protocol selected for OTA control operations. * This configuration parameter sets the default protocol for all the OTA control * operations like requesting OTA job, updating the job status etc. * * Note - Only MQTT is supported at this time for control operations. */ #define configENABLED_CONTROL_PROTOCOL ( OTA_CONTROL_OVER_MQTT ) /** * @brief The protocol selected for OTA data operations. * This configuration parameter sets the protocols selected for the data operations * like requesting file blocks from the service. * * Note - Both MQTT and HTTP are supported for data transfer. This configuration parameter * can be set to the following - * Enable data over MQTT - ( OTA_DATA_OVER_MQTT ) * Enable data over HTTP - ( OTA_DATA_OVER_HTTP) * Enable data over both MQTT & HTTP ( OTA_DATA_OVER_MQTT | OTA_DATA_OVER_HTTP ) */ #define configENABLED_DATA_PROTOCOLS ( OTA_DATA_OVER_MQTT ) /** * @brief The preferred protocol selected for OTA data operations. * * Primary data protocol will be the protocol used for downloading files if more than * one protocol is selected while creating OTA job. Default primary data protocol is MQTT * and the following update here switches to HTTP as primary. * * Note - use OTA_DATA_OVER_HTTP for HTTP as primary data protocol. */ #define configOTA_PRIMARY_DATA_PROTOCOL ( OTA_DATA_OVER_MQTT )
裝置特定的組態
無。
記憶體用量
當 MQTT 用於資料傳輸時,MQTT 連線不需要額外的記憶體,因為它是在控制操作與資料操作之間共用。
裝置政策
使用 MQTT 接收 OTA 更新的每個裝置都必須在 中註冊為物件, AWS IoT 而且物件必須具有類似此處列出的附加政策。如需 "Action"
和 "Resource"
物件中的項目的詳細資訊,請參閱 AWS IoT
核心政策動作和 AWS IoT 核心動作資源。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "iot:Connect", "Resource": "arn:
partition
:iot:region
:account
:client/${iot:Connection.Thing.ThingName}" }, { "Effect": "Allow", "Action": "iot:Subscribe", "Resource": [ "arn:partition
:iot:region
:account
:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/streams/*", "arn:partition
:iot:region
:account
:topicfilter/$aws/things/${iot:Connection.Thing.ThingName}/jobs/*" ] }, { "Effect": "Allow", "Action": [ "iot:Publish", "iot:Receive" ], "Resource": [ "arn:partition
:iot:region
:account
:topic/$aws/things/${iot:Connection.Thing.ThingName}/streams/*", "arn:partition
:iot:region
:account
:topic/$aws/things/${iot:Connection.Thing.ThingName}/jobs/*" ] } ] }
備註
-
iot:Connect
許可允許您的裝置 AWS IoT 透過 MQTT 連線至 。 -
AWS IoT 任務 (
.../jobs/*
) 主題的iot:Subscribe
和iot:Publish
許可允許連線的裝置接收任務通知和任務文件,以及發佈任務執行的完成狀態。 -
OTA 串流 (
.../streams/*
) AWS IoT 主題的iot:Subscribe
和iot:Publish
許可允許連線的裝置從中擷取 OTA 更新資料 AWS IoT。需要這些許可才能透過 MQTT 執行韌體更新。 -
iot:Receive
許可允許 AWS IoT Core 在這些主題上發佈訊息到連線的裝置。每次交付 MQTT 訊息時,都會檢查此許可。您可以使用此許可來撤銷目前訂閱主題之用戶端的存取權。