0
0
IOT Protocolsdevops~10 mins

Device shadow (digital twin) in IOT Protocols - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Device shadow (digital twin)
Device Shadow Service
Receive Desired State Update
Update Shadow Document
Notify Device of Desired State
Device Applies Changes
Device Reports Reported State
Update Shadow Document with Reported State
Clients Read Updated Shadow
The device shadow service keeps a virtual copy of device state. It updates when clients or devices change state, syncing desired and reported states.
Execution Sample
IOT Protocols
1. Client updates desired state: {"light": "on"}
2. Shadow service updates shadow document
3. Device receives desired state
4. Device turns light on
5. Device reports reported state: {"light": "on"}
6. Shadow service updates shadow document
Shows how a client changes desired state, device applies it, and reports back, updating the shadow.
Process Table
StepActionShadow Document Desired StateShadow Document Reported StateDevice StateOutput/Result
1Client sets desired state to {"light": "on"}{"light": "on"}{}offShadow document desired state updated
2Shadow service notifies device of desired state{"light": "on"}{}offDevice receives desired state {"light": "on"}
3Device applies desired state{"light": "on"}{}onDevice turns light on
4Device reports reported state {"light": "on"}{"light": "on"}{"light": "on"}onShadow document reported state updated
5Clients read updated shadow{"light": "on"}{"light": "on"}onClients see device is on
6No further changes{"light": "on"}{"light": "on"}onExecution ends
💡 No more updates; desired and reported states are synchronized.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
Desired State{}{"light": "on"}{"light": "on"}{"light": "on"}{"light": "on"}{"light": "on"}
Reported State{}{}{}{}{"light": "on"}{"light": "on"}
Device Stateoffoffoffononon
Key Moments - 2 Insights
Why does the shadow document have separate desired and reported states?
Because the desired state shows what clients want the device to do, while the reported state shows what the device has actually done. This separation helps track if the device is in sync with client requests, as seen in steps 1 and 4 of the execution table.
What happens if the device cannot apply the desired state?
The device will not update the reported state to match the desired state, so the shadow document shows a difference between desired and reported states. This difference signals clients that the device is not yet in the desired state, as would be visible if step 4 did not update reported state.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the device state after step 3?
Aunknown
Bon
Coff
D{}
💡 Hint
Check the 'Device State' column at step 3 in the execution table.
At which step does the shadow document's reported state get updated?
AStep 4
BStep 1
CStep 3
DStep 5
💡 Hint
Look for when the 'Reported State' column changes from empty to {"light": "on"}.
If the device never reports its state, what will the shadow document show?
ADevice state will automatically update
BDesired and reported states will be the same
CReported state will remain empty while desired state updates
DShadow document will delete desired state
💡 Hint
Refer to variable_tracker rows for 'Reported State' and 'Desired State' changes.
Concept Snapshot
Device Shadow (Digital Twin):
- A virtual copy of device state stored in the cloud.
- Has separate 'desired' and 'reported' states.
- Clients update desired state to request changes.
- Device reads desired state, applies changes, reports back.
- Shadow syncs states to reflect real device condition.
Full Transcript
Device shadow is a cloud service that keeps a virtual copy of a device's state. It stores two parts: desired state, which clients want the device to have, and reported state, which shows what the device actually has. When a client updates the desired state, the shadow service notifies the device. The device then applies the changes and reports its new state back. The shadow updates the reported state accordingly. This process helps keep clients and devices in sync, even if the device is offline temporarily. The execution table shows each step: client sets desired state, device receives it, applies it, reports back, and clients read the updated shadow. Variables track how desired state, reported state, and device state change over time. Key points include understanding why desired and reported states are separate and what happens if the device cannot apply changes. The visual quiz tests understanding of device state changes and shadow updates.