AWS Device Shadow
Table of contents
We have clearly identified that IOT Devices totally rely on electricity to communicate with each other and to be able to use cloud services such as AWS.
In other words, when a publication is made by a device, the subscribing devices get the new state immediately if online.
Suppose it goes off, how then can we be then operating or rather bridge the gap?
Device shadows are some of these solutions. If your device subscribing to a topic in the cloud loses power, then it cannot receive real-time updates. So if it comes back online when a particular state changed at a certain time. It may have missed it.
So for it to be able to get the current state, it might have to wait for the next publication. Suppose that' a year, it would not make much sense.
To combat this, we have the device shadow to store the current or last updated state of the device, such that any service that needs this state does not have to wait until the next publish.
To create a device shadow head to the thing you created.
Under Device shadows click create and choose a shadow. For starters, lets create an unnamed shadow.
A classic shadow will be created. Tap on the shadow name.
Scroll down to the shadow document. Notice the shadow contains a state property that describes these aspects of the device’s state:
desired -done by the app/user such as a setting
Apps specify the desired states of device properties by updating the
desired
object.reported -done by the device in response to setting received
Devices report their current state in the
reported
object.delta
AWS IoT reports differences between the desired and the reported state in the
delta
object.
Click the edit button to add fields to the shadow and click update.
The shadow attributes must now have changed to include the new attribute e.g "lights" : "false"
Now you can access your lights attribute by using state object.state.desired.lights and set the new value.
With this, you can now set up a device shadow and add attributes to it.
Subscribe to my newsletter
Read articles from Emmilly Immaculate Namuganga directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Emmilly Immaculate Namuganga
Emmilly Immaculate Namuganga
I fell for mobile apps, cloud, and IoT. I love learning and eating.