I have an app that subscribes and publishes to topics on aws IoT. I am wondering what the difference between the two classes "device" and "thingShadow" are. This library gives examples of both and they both seem to have similar functionalities.
-
Hi, I posted an answer to your question. In order for other people to consider it relevant, would you mind accepting it if it helped ? – Halim Qarroum Jul 08 '17 at 14:47
-
could you expand more on the terms you used, it wasn't that helpful since I'm new to aws IoT and am not familiar with terminology yet – Jul 08 '17 at 20:30
-
I have updated my answer to give context on the terms I have employed, namely, MQTT topics communication, and the thing shadow. – Halim Qarroum Jul 08 '17 at 23:58
1 Answers
The device class is used to subscribe to and publish messages on MQTT topics for telemetry and messaging purposes.
The 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.
So basically, if you're using device shadows use the thingShadow
class, otherwise you can use the device
class.
EDIT:
To expand a bit more on the basic principles of AWS IoT, you have two communication scheme between devices:
Since AWS IoT implements a standard MQTT interface, you can use topics to communicate with your devices using a pattern called publish-subscribe. Your apps can subscribe to a topic and wait for a device to publish a message on it. Similarly, your app can publish a message on a device topic and have the device receive it.
AWS IoT implements a second communication interface called the device shadow, which allows you to address a device even when it is disconnected, and keep a synchronized state between your app and the device itself. The AWS documentation explains it in clear terms.
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.
The two interfaces can be addressed in the SDK using the device class for subscribing and publishing on MQTT topics, and the thing shadow class to retrieve, update or delete a device thing shadow document.

- 13,985
- 4
- 46
- 71