sensors. The frequency of sending a PUBLISH packet can be decided by the user application. The application is
written such that the sensor data is published to the Cloud every second.
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'.
1.
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:
{
}
– 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.
2.
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:
{
}
– 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.
{
}
Further information can be found here:
Note: Remember to replace thingName with the device's actual thing name.
2.4.2
Subscribing to AWS Shadow Topic
To get information about the device's shadow from the shadow service, the device has to subscribe to specific
shadow topics. More information on shadow topics can be found here at
©
2020 Microchip Technology Inc.
"state"
:
{
"reported"
:
{
"toggle"
: 1
}
}
"state"
:
{
"desired"
:
{
"toggle"
: 1
}
}
"state"
:
{
"reported"
:
{
"toggle"
: 1
}
}
/update
AVR-IoT WA User Guide
Shadow MQTT
User Guide
Getting Started
topics.
DS50002998A-page 10
Need help?
Do you have a question about the AVR-IoT WA and is the answer not in the manual?
Questions and answers