0
0
IOT Protocolsdevops~10 mins

Retained messages 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 publish a retained message in MQTT.

IOT Protocols
client.publish('home/temperature', '22', retain=[1])
Drag options to blanks, or click blank then click option'
AFalse
B0
CNone
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using retain=False will not keep the message for new subscribers.
2fill in blank
medium

Complete the code to subscribe to a topic and receive retained messages.

IOT Protocols
client.subscribe('[1]')
Drag options to blanks, or click blank then click option'
Ahome/temperature
Bhome/temperature/last
Chome/temperature/retained
Dhome/temperature/#
Attempts:
3 left
💡 Hint
Common Mistakes
Using wildcards may not receive the retained message as expected.
3fill in blank
hard

Fix the error in the code to clear a retained message by publishing an empty payload.

IOT Protocols
client.publish('home/temperature', [1], retain=True)
Drag options to blanks, or click blank then click option'
A0
BNone
C''
D' '
Attempts:
3 left
💡 Hint
Common Mistakes
Using None or a space character does not clear the retained message.
4fill in blank
hard

Fill both blanks to create a retained message dictionary with topic and payload.

IOT Protocols
{'topic': '[1]', 'payload': '[2]'}
Drag options to blanks, or click blank then click option'
Ahome/temperature
B22
Chome/humidity
D45
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping topic and payload values or using incorrect topic names.
5fill in blank
hard

Fill all three blanks to filter retained messages with payload greater than 20.

IOT Protocols
retained_msgs = {msg['topic']: msg['payload'] for msg in messages if int(msg['payload']) [1] [2] and msg.get('retain', False) == [3]
Drag options to blanks, or click blank then click option'
A>
B20
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or checking retain flag incorrectly.