Challenge - 5 Problems
MQTT QoS Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
MQTT QoS 0 Message Delivery
What will be the output on the subscriber console when a message is published with QoS 0?
Raspberry Pi
import paho.mqtt.client as mqtt # Callback when a message is received def on_message(client, userdata, msg): print(f"Received message: {msg.payload.decode()} with QoS {msg.qos}") client = mqtt.Client() client.on_message = on_message client.connect("test.mosquitto.org", 1883, 60) client.subscribe("test/qos0", qos=0) client.loop_start() publisher = mqtt.Client() publisher.connect("test.mosquitto.org", 1883, 60) publisher.publish("test/qos0", payload="Hello QoS0", qos=0) import time time.sleep(2) client.loop_stop()
Attempts:
2 left
💡 Hint
QoS 0 means the message is delivered at most once without acknowledgment.
✗ Incorrect
QoS 0 delivers the message once without confirmation. The subscriber receives the message with QoS 0.
❓ Predict Output
intermediate2:00remaining
MQTT QoS 1 Message Acknowledgment
What output will the subscriber show when a message is published with QoS 1?
Raspberry Pi
import paho.mqtt.client as mqtt def on_message(client, userdata, msg): print(f"Received message: {msg.payload.decode()} with QoS {msg.qos}") client = mqtt.Client() client.on_message = on_message client.connect("test.mosquitto.org", 1883, 60) client.subscribe("test/qos1", qos=1) client.loop_start() publisher = mqtt.Client() publisher.connect("test.mosquitto.org", 1883, 60) publisher.publish("test/qos1", payload="Hello QoS1", qos=1) import time time.sleep(2) client.loop_stop()
Attempts:
2 left
💡 Hint
QoS 1 guarantees message delivery at least once with acknowledgment.
✗ Incorrect
With QoS 1, the subscriber receives the message and the QoS level is 1, confirming acknowledgment.
🧠 Conceptual
advanced2:00remaining
MQTT QoS 2 Message Flow
Which sequence correctly describes the MQTT QoS 2 message delivery handshake between publisher and broker?
Attempts:
2 left
💡 Hint
QoS 2 ensures exactly once delivery with a four-step handshake.
✗ Incorrect
The correct order is PUBLISH, PUBREC, PUBREL, then PUBCOMP to guarantee exactly once delivery.
❓ Predict Output
advanced2:00remaining
Effect of QoS Level on Message Duplication
If a publisher sends a message with QoS 1 and the subscriber receives it twice, what is the likely cause?
Attempts:
2 left
💡 Hint
QoS 1 ensures delivery at least once, so duplicates can happen.
✗ Incorrect
QoS 1 may deliver duplicates if acknowledgments are lost, causing retransmission.
🔧 Debug
expert3:00remaining
Debugging MQTT QoS 2 Message Loss
Given this code snippet, why might the subscriber never receive messages published with QoS 2?
client.subscribe("test/qos2", qos=2)
# on_message callback is missing
client.loop_forever()
Raspberry Pi
import paho.mqtt.client as mqtt client = mqtt.Client() client.connect("test.mosquitto.org", 1883, 60) client.subscribe("test/qos2", qos=2) client.loop_forever()
Attempts:
2 left
💡 Hint
Without an on_message callback, messages arrive but are ignored silently.
✗ Incorrect
The client subscribes correctly but does not define on_message, so no output or processing occurs.