0
0
IOT Protocolsdevops~6 mins

Device shadow (digital twin) in IOT Protocols - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine trying to control or check the status of a device that is far away or temporarily offline. Without a way to keep track of its state, managing such devices becomes confusing and unreliable. Device shadows solve this problem by acting as a virtual copy of the device's current state.
Explanation
Virtual Representation
A device shadow is a virtual version of a physical device stored in the cloud or a server. It keeps track of the device's last known state, even when the device is offline or unreachable. This allows applications to interact with the device's state without needing the device to be connected at that moment.
Device shadows provide a virtual copy of a device's state that is always accessible.
Desired and Reported States
The device shadow stores two main pieces of information: the desired state and the reported state. The desired state is what the user or application wants the device to be. The reported state is what the device actually is. The system compares these to know if the device needs to change.
Device shadows track both what is wanted and what the device currently reports.
Synchronization Process
When the device connects, it checks the shadow for any differences between desired and reported states. It then updates itself to match the desired state and reports back its new state. This keeps the shadow and device in sync, even if the device was offline for a while.
Device shadows help synchronize device state changes smoothly after disconnections.
Use in IoT Systems
Device shadows are widely used in Internet of Things (IoT) systems to manage many devices remotely. They simplify communication by letting applications read and write device states without direct device interaction. This improves reliability and user experience.
Device shadows enable reliable remote management of IoT devices.
Real World Analogy

Imagine you have a smart home light bulb that you want to turn on while you are away. The light bulb might be offline when you send the command. A device shadow acts like a note on your fridge that says 'Turn the light on.' When the bulb comes back online, it reads the note and turns on accordingly.

Virtual Representation → The note on the fridge representing the light bulb's state
Desired and Reported States → The note saying 'Turn the light on' (desired) and the bulb actually being on or off (reported)
Synchronization Process → The bulb reading the note and changing its state when it returns home
Use in IoT Systems → Managing many smart devices in a home using notes to keep track of their states
Diagram
Diagram
┌───────────────┐       ┌───────────────┐
│   Application │──────▶│ Device Shadow │
└───────────────┘       └───────────────┘
                              ▲   │
                              │   │
                       Desired│   │Reported
                              │   ▼
                      ┌─────────────────┐
                      │  Physical Device │
                      └─────────────────┘
Diagram showing the application interacting with the device shadow, which synchronizes with the physical device's desired and reported states.
Key Facts
Device ShadowA virtual copy of a physical device's state stored remotely.
Desired StateThe state that an application wants the device to have.
Reported StateThe actual state the device reports back.
SynchronizationThe process of updating the device to match the desired state and reporting back.
Offline Device HandlingDevice shadows allow state changes to be queued when devices are offline.
Common Confusions
Device shadow is the device itself.
Device shadow is the device itself. The device shadow is only a virtual copy stored remotely; the physical device is separate and may be offline.
Desired state always matches reported state instantly.
Desired state always matches reported state instantly. There can be delays; the device updates reported state only when it connects and processes changes.
Summary
Device shadows act as virtual copies of physical devices to track their state remotely.
They store desired and reported states to manage device behavior and synchronization.
This system allows reliable control and monitoring of devices even when they are offline.