0
0
Raspberry Piprogramming~10 mins

MQTT with QoS levels in Raspberry Pi - Interactive Code Practice

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

Complete the code to set the MQTT QoS level to 1 when publishing a message.

Raspberry Pi
client.publish('sensor/data', payload='temperature', qos=[1])
Drag options to blanks, or click blank then click option'
A0
B2
C1
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using QoS 0 when message delivery guarantee is needed.
Using QoS 3 which is invalid.
2fill in blank
medium

Complete the code to subscribe to the topic 'home/livingroom' with QoS level 2.

Raspberry Pi
client.subscribe('home/livingroom', qos=[1])
Drag options to blanks, or click blank then click option'
A2
B1
C0
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using QoS 3 which is not a valid MQTT QoS level.
Confusing QoS 1 and QoS 2.
3fill in blank
hard

Fix the error in the code to correctly publish a message with QoS 0.

Raspberry Pi
client.publish('alerts', payload='fire detected', qos=[1])
Drag options to blanks, or click blank then click option'
A1
B-1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using negative QoS values.
Using QoS 3 which is invalid.
4fill in blank
hard

Fill both blanks to create a subscription with QoS 1 and publish a message with QoS 2.

Raspberry Pi
client.subscribe('devices/status', qos=[1])
client.publish('devices/status', payload='online', qos=[2])
Drag options to blanks, or click blank then click option'
A1
B0
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid QoS 3.
Mixing up QoS levels for subscribe and publish.
5fill in blank
hard

Fill all three blanks to publish a message with QoS 1, subscribe with QoS 0, and publish another message with QoS 2.

Raspberry Pi
client.publish('alerts', payload='low battery', qos=[1])
client.subscribe('alerts', qos=[2])
client.publish('alerts', payload='battery critical', qos=[3])
Drag options to blanks, or click blank then click option'
A0
B1
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid QoS 3.
Confusing QoS levels between publish and subscribe.