2.4.1.1 Updating the Device Shadow
In order to control the device from the Cloud, the AWS Shadow Service feature is used. The AWS Shadow service maintains a shadow of the device in the form of a JSON document. The device’s state can be stored and retrieved, leveraging upon the AWS Shadow Topics. To set and get the state of the device, either HTTP or MQTT can be used. For the demo application, MQTT protocol is chosen. Each device is represented by its unique thing name.
To update the device’s shadow, publish on the topic
‘
$aws/things/thingName/shadow/update
’.- Device updating its reported
state:
- The device would publish
on this topic to update the state of its reported attributes. Below is
an example of a payload where ‘toggle’ is the
attribute:
{ "state" : { "reported" : { "toggle" : 1 } } }
- The payload consists of key-value pairs. In the above example, attribute ‘toggle’ is set to ‘1’. The user can expand the application to add more attributes, which requires updates in the firmware.
- The device would publish
on this topic to update the state of its reported attributes. Below is
an example of a payload where ‘toggle’ is the
attribute:
- Client requesting to update a
device shadow:
- To request a change in
attribute value, the client will publish on the same topic and the
payload will
be:
{ "state" : { "desired" : { "toggle" : 1 } } }
- The payload consists of
key-value pairs. In the above example, attribute ‘toggle’ is set to ‘1’.
The user can expand the application to add more attributes, which
requires updates in the
firmware.
{ "state" : { "reported" : { "toggle" : 1 } } }
- To request a change in
attribute value, the client will publish on the same topic and the
payload will
be:
Further information can be found here: /update
Note: Remember to replace thingName with
the device's actual thing name.