同步客户端设备阴影并与之交互 - Amazon IoT Greengrass
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

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

同步客户端设备阴影并与之交互

您可以将卷影管理器组件管理本地阴影,包括客户端设备阴影。您可以部署和配置此卷影管理器组件以执行以下操作:

注意

阴影管理器组件不同步阴影与 Amazon IoT Core 默认情况下。必须配置卷影管理器组件以指定要同步的客户端设备阴影。

默认情况下,卷影管理器组件不管理客户端设备阴影。若要启用此功能,必须将 MQTT 消息从客户端设备中继到卷影管理器组件。客户端设备使用 MQTT 消息接收和发送设备卷影更新。影子管理器组件订阅本地 Greengrass 发布/订阅界面,因此您可以配置MQTT 桥组件中继有关设备影子主题的 MQTT 消息。有关更多信息,请参阅 。影子主题中的 Amazon IoT Core 开发人员指南

配置和部署 MQTT 桥组件

MQTT 桥组件使用主题映射列表,每个映射都指定消息源和消息目标。要使卷影管理器组件能够管理客户端设备阴影,请部署 MQTT 桥组件,并指定要管理的客户端设备阴影的影子主题。您必须将网桥配置为在本地 MQTT 和本地发布/订阅之间双向中继消息。

要将 MQTT 桥接组件部署到核心设备或核心设备组,创建部署,其中包含aws.greengrass.clientdevices.mqtt.Bridge组件。指定主题映射,mqttTopicMapping在部署中的 MQTT 桥组件配置中。

注意

您可以使用这些配置示例在Amazon IoT Greengrass控制台。如果您使用Amazon IoT GreengrassAPI、merge配置更新需要序列化的 JSON 对象,因此您必须将以下 JSON 对象序列化为字符串。有关更多信息,请参阅 更新组件配置

要使用卷影管理器管理客户端设备的未命名阴影,请为要同步的每个客户端设备指定以下每个主题。ReplacethingName,其中包含要管理的客户端设备的名称。

{ "mqttTopicMapping": { "DeleteShadow": { "topic": "$aws/things/thingName/shadow/delete", "source": "LocalMqtt", "target": "Pubsub" }, "DeleteShadowAccepted": { "topic": "$aws/things/thingName/shadow/delete/accepted", "source": "Pubsub", "target": "LocalMqtt" }, "DeleteShadowRejected": { "topic": "$aws/things/thingName/shadow/delete/rejected", "source": "Pubsub", "target": "LocalMqtt" }, "GetShadow": { "topic": "$aws/things/thingName/shadow/get", "source": "LocalMqtt", "target": "Pubsub" }, "GetShadowAccepted": { "topic": "$aws/things/thingName/shadow/get/accepted", "source": "Pubsub", "target": "LocalMqtt" }, "GetShadowRejected": { "topic": "$aws/things/thingName/shadow/get/rejected", "source": "Pubsub", "target": "LocalMqtt" }, "UpdateShadow": { "topic": "$aws/things/thingName/shadow/update", "source": "LocalMqtt", "target": "Pubsub" }, "UpdateShadowAccepted": { "topic": "$aws/things/thingName/shadow/update/accepted", "source": "Pubsub", "target": "LocalMqtt" }, "UpdateShadowRejected": { "topic": "$aws/things/thingName/shadow/update/rejected", "source": "Pubsub", "target": "LocalMqtt" }, "UpdateShadowResponseDelta": { "topic": "$aws/things/thingName/shadow/update/delta", "source": "Pubsub", "target": "LocalMqtt" }, "UpdateShadowResponseDocuments": { "topic": "$aws/things/thingName/shadow/update/documents", "source": "Pubsub", "target": "LocalMqtt" } } }

要使用卷影管理器管理客户端设备的命名阴影,请为要同步的每个命名阴影指定以下主题。ReplacethingNameshadowName在以下 MQTT 桥组件配置中,其中包含要管理的客户端设备和影子的名称。

{ "mqttTopicMapping": { "DeleteNamedShadow": { "topic": "$aws/things/thingName/shadow/name/shadowName/delete", "source": "LocalMqtt", "target": "Pubsub" }, "DeleteNamedShadowAccepted": { "topic": "$aws/things/thingName/shadow/name/shadowName/delete/accepted", "source": "Pubsub", "target": "LocalMqtt" }, "DeleteNamedShadowRejected": { "topic": "$aws/things/thingName/shadow/name/shadowName/delete/rejected", "source": "Pubsub", "target": "LocalMqtt" }, "GetNamedShadow": { "topic": "$aws/things/thingName/shadow/name/shadowName/get", "source": "LocalMqtt", "target": "Pubsub" }, "GetNamedShadowAccepted": { "topic": "$aws/things/thingName/shadow/name/shadowName/get/accepted", "source": "Pubsub", "target": "LocalMqtt" }, "GetNamedShadowRejected": { "topic": "$aws/things/thingName/shadow/name/shadowName/get/rejected", "source": "Pubsub", "target": "LocalMqtt" }, "UpdateNamedShadow": { "topic": "$aws/things/thingName/shadow/name/shadowName/update", "source": "LocalMqtt", "target": "Pubsub" }, "UpdateNamedShadowAccepted": { "topic": "$aws/things/thingName/shadow/name/shadowName/update/accepted", "source": "Pubsub", "target": "LocalMqtt" }, "UpdateNamedShadowRejected": { "topic": "$aws/things/thingName/shadow/name/shadowName/update/rejected", "source": "Pubsub", "target": "LocalMqtt" }, "UpdateNamedShadowResponseDelta": { "topic": "$aws/things/thingName/shadow/name/shadowName/update/delta", "source": "Pubsub", "target": "LocalMqtt" }, "UpdateNamedShadowResponseDocuments": { "topic": "$aws/things/thingName/shadow/name/shadowName/update/documents", "source": "Pubsub", "target": "LocalMqtt" } } }