aws IoT 'device' 和 'thingShadow' 类 有什么区别?

What is the difference between aws IoT 'device' and 'thingShadow' classes?

我有一个应用程序可以订阅和发布 aws IoT 上的主题。我想知道 类 “device” 和 “thingShadow” 这两个有什么区别。 library 给出了两者的示例,它们似乎都具有相似的功能。

device class 用于在 MQTT 主题上订阅和发布消息,用于遥测和消息传递目的。

thingShadow class is a wrapper around the device class, which provides additional methods such as .register, .update or delete which are designed to interact with a device shadow. This class also emits specific events associated with a shadow lifecycle such as status, delta or foreignStateChange.

[...] the thingShadow class allows devices to update, be notified of changes to, get the current state of, or delete Thing Shadows from AWS IoT.

所以基本上,如果您使用设备阴影,请使用 thingShadow class,否则您可以使用 device class.

编辑:

为了进一步扩展 AWS IoT 的基本原理,您有两种设备之间的通信方案:

  • 由于 AWS IoT 实施标准 MQTT interface, you can use topics to communicate with your devices using a pattern called publish-subscribe。您的应用程序可以订阅一个主题并等待设备在其上发布消息。同样,您的应用可以发布有关设备主题的消息并让设备接收它。

  • AWS IoT 实现了称为 device shadow 的第二个通信接口,它允许您在设备断开连接时对其进行寻址,并在您的应用程序和设备本身之间保持同步状态. AWS 文档对其进行了明确的解释。

A thing shadow (sometimes referred to as a device shadow) is a JSON document that is used to store and retrieve current state information for a thing (device, app, and so on). The Thing Shadows service maintains a thing shadow for each thing you connect to AWS IoT. You can use thing shadows to get and set the state of a thing over MQTT or HTTP, regardless of whether the thing is connected to the Internet. Each thing shadow is uniquely identified by its name.

这两个接口可以在 SDK 中使用 device class 来订阅和发布 MQTT 主题,并使用 thing shadow class 来检索, 更新或删除设备物影文件。