You can get the state of your device using AWS IoT service Device Shadow. Device shadow is the virtual representation of your physical device. It is a JSON document that is used to store and access current state information of a device. This service maintains a shadow (virtual Device State) for every device you connect to AWS IoT Platform. You can use the shadow document to get the current state of the device and based on that state, you can take any action on the device. We can also monitor and control our Devices based on our needs over (MQTT or HTTP) protocols, regardless of whether the device is connected to the Internet. The current state data of the device will be synchronized with the cloud once the IoT Device is connected to the internet. Each device’s shadow is uniquely identified by the name of the corresponding Thing (Device connected with AWS IoT).
How can I get the latest state of my IoT Device?
- Device publishes current state of the device weather is ‘ON’ of ‘OFF’.
- This persist JSON state data stores in AWS IoT Platform.
- Application requests device Current State.
- User/Application requests to change the state of the device based on requirement.
- Device Shadow sync’s updated state and changes the requested state.
- Device publishes current state which is nothing but Reported State.
- Device Shadow conforms state change with updated state of the device.
Let us consider a Motor (or any smart device) which is connected to a relay and then to IoT Device Gateway (Raspberry Pi in this case). The user (or) the Application request to AWS IoT Platform for the current Motor state to check whether it is ‘ON’ or ‘OFF’, based on the get Shadow state App request, the last updated Device state from the Shadow JSON doc was sent to App. The Shadow Document on the AWS IoT Platform keeps track of the device state, version, timestamp, every time the state changes the same change happens on the cloud once the device gets connected to the internet. IoT Device (Raspberry Pi) sends current, desired and reported the state of the Device(motor) to AWS IoT Platform using AWS IoT Device Shadow SDK, which is running on the Raspberry Pi. Based on the current state of the motor, the App or user shall take the decision to change the state of the motor (Turn motor/device ‘ON’ or ‘OFF’) based on the requirement to have fine-grained control on IoT Devices.
AWS IoT Device Shadow can really help us to build a complete ecosystem on the devices and cloud where we can have IoT device state information and based on that we can control the device. We can also store these state data for Predictive Analysis.