0
0
IOT Protocolsdevops~10 mins

Device shadow (digital twin) in IOT Protocols - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to update the device shadow state with the reported temperature.

IOT Protocols
shadow_update = {"state": {"reported": {"temperature": [1]
Drag options to blanks, or click blank then click option'
A"22"
Btemperature
Ctemp
D22
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number, making it a string instead of a number.
2fill in blank
medium

Complete the code to retrieve the desired state from the device shadow JSON.

IOT Protocols
desired_state = shadow_document["state"][[1]]
Drag options to blanks, or click blank then click option'
A"reported"
B"desired"
C"current"
D"status"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'reported' instead of 'desired' key.
3fill in blank
hard

Fix the error in the code to correctly publish the shadow update to the MQTT topic.

IOT Protocols
mqtt_client.publish("$aws/things/[1]/shadow/update", json.dumps(shadow_update))
Drag options to blanks, or click blank then click option'
Athing_name
Bdevice-name
CthingName
Ddevice_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names that don't match the thing name.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters reported states with temperature above 25.

IOT Protocols
{k: v for k, v in shadow_state[[1]].items() if v [2] 25}
Drag options to blanks, or click blank then click option'
A"reported"
B>
C<
D"desired"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'desired' instead of 'reported'.
Using '<' instead of '>'.
5fill in blank
hard

Fill all three blanks to create a shadow update payload with desired humidity set to 60 and reported temperature unchanged.

IOT Protocols
shadow_payload = {"state": {"desired": {"humidity": [1], "reported": {"temperature": [2], "clientToken": [3]
Drag options to blanks, or click blank then click option'
A60
Bcurrent_temp
C"token123"
D"60"
Attempts:
3 left
💡 Hint
Common Mistakes
Using string '60' instead of number 60.
Using wrong variable for temperature.
Missing quotes around clientToken string.