0
0
IOT Protocolsdevops~15 mins

Device shadow (digital twin) in IOT Protocols - Mini Project: Build & Apply

Choose your learning style9 modes available
Device Shadow (Digital Twin) Simulation
📖 Scenario: You are managing smart home devices remotely. Each device has a device shadow, a digital copy of its state stored in the cloud. This shadow helps you track and control the device even when it is offline.In this project, you will simulate a simple device shadow using a dictionary to represent the device's reported and desired states.
🎯 Goal: Build a small program that creates a device shadow dictionary, sets a desired state, updates the reported state, and finally prints the current shadow state.
📋 What You'll Learn
Create a dictionary called device_shadow with keys reported and desired, both starting as empty dictionaries.
Add a desired state for temperature set to 22 degrees.
Update the reported state with temperature set to 20 degrees.
Print the complete device_shadow dictionary to show current states.
💡 Why This Matters
🌍 Real World
Device shadows are used in IoT to keep a cloud copy of a device's state. This helps users control devices remotely and handle offline scenarios.
💼 Career
Understanding device shadows is important for IoT developers and DevOps engineers managing connected devices and cloud services.
Progress0 / 4 steps
1
Create the initial device shadow dictionary
Create a dictionary called device_shadow with two keys: reported and desired. Both should be empty dictionaries.
IOT Protocols
Need a hint?

Think of device_shadow as a box with two smaller boxes inside: one for what the device says (reported) and one for what you want it to do (desired).

2
Set the desired temperature state
Add a key temperature with value 22 inside the desired dictionary of device_shadow.
IOT Protocols
Need a hint?

Use device_shadow["desired"]["temperature"] = 22 to set the desired temperature.

3
Update the reported temperature state
Add a key temperature with value 20 inside the reported dictionary of device_shadow.
IOT Protocols
Need a hint?

Use device_shadow["reported"]["temperature"] = 20 to update the reported temperature.

4
Print the device shadow
Print the device_shadow dictionary to display the current reported and desired states.
IOT Protocols
Need a hint?

Use print(device_shadow) to show the current device shadow.