本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 MQTT 的 OTA 更新的先决条件
重要
这是《FreeRTOS 用户指南》的存档版本,可用于 FreeRTOS 版本 202012.00。有关本文档的最新版本,请参阅《FreeRTOS 用户指南》。
本节介绍使用 MQTT 执行任务的一般要求 over-the-air(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 并且该设备必须附有类似于此处列出的策略。您可以在 AWS IoT
核心策略操作和 AWS IoT 核心操作资源中找到有关 "Action"
和 "Resource"
对象中项目的更多信息。
{ "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
权限允许您的设备通过 MQTT AWS IoT 进行连接。 -
AWS IoT 任务主题的
iot:Subscribe
和iot:Publish
权限 (.../jobs/*
) 允许连接的设备接收作业通知和作业文档,并发布任务执行的完成状态。 -
AWS IoT OTA 直播主题的
iot:Subscribe
和iot:Publish
权限 (.../streams/*
) 允许连接的设备从中获取 OTA 更新数据 AWS IoT。在通过 MQTT 执行固件更新时,需要这些权限。 -
这些
iot:Receive
权限 AWS IoT Core 允许将有关这些主题的消息发布到连接的设备。每次传输 MQTT 消息时,都将检查此权限。您可以使用此权限,撤消对当前订阅主题的客户端的访问权限。