Bird
0
0

Consider this Python code snippet using Paho MQTT client:

medium📝 Predict Output Q13 of 15
Raspberry Pi - MQTT for IoT
Consider this Python code snippet using Paho MQTT client:
client.publish('sensor/data', 'temp=22', qos=0)
client.publish('sensor/data', 'temp=23', qos=1)
client.publish('sensor/data', 'temp=24', qos=2)
What is the expected behavior regarding message delivery?
AAll messages are delivered exactly once
BFirst message may be lost, second delivered at least once, third exactly once
CAll messages may be lost without retry
DFirst message delivered at least once, others may be duplicated
Step-by-Step Solution
Solution:
  1. Step 1: Analyze QoS 0 message delivery

    QoS 0 means message sent once, no retry, may be lost.
  2. Step 2: Analyze QoS 1 and QoS 2 messages

    QoS 1 guarantees at least once delivery (may duplicate), QoS 2 guarantees exactly once delivery.
  3. Final Answer:

    First message may be lost, second delivered at least once, third exactly once -> Option B
  4. Quick Check:

    QoS 0=may lose, QoS 1=at least once, QoS 2=exactly once [OK]
Quick Trick: Remember QoS 0 no retry, QoS 1 retry, QoS 2 handshake [OK]
Common Mistakes:
MISTAKES
  • Assuming QoS 0 always delivers
  • Confusing QoS 1 with exactly once
  • Ignoring possible duplicates at QoS 1

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes