Bird
Raised Fist0
IOT Protocolsdevops~10 mins

QoS levels (0, 1, 2) in IOT Protocols - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - QoS levels (0, 1, 2)
Start: Publish Message
↓
Check QoS Level
↓
QoS 0
↓
Send
↓
No Ack
↓
Done
↓
Done
The flow shows how a message is published with different QoS levels, each with increasing delivery guarantees and acknowledgement steps.
Execution Sample
IOT Protocols
Publish message with QoS 1
Send message
Wait for PUBACK
If no PUBACK, resend
End
This code simulates sending a message with QoS 1, waiting for an acknowledgement, and retrying if needed.
Process Table
StepQoS LevelActionAcknowledgementResult
10Send message onceNo ack expectedMessage sent, no retry
21Send messageWait for PUBACKIf PUBACK received, done
31No PUBACK receivedTimeoutResend message
41PUBACK received after resendPUBACK receivedDone
52Send PUBLISH messageWait for PUBRECIf PUBREC received, send PUBREL
62Send PUBRELWait for PUBCOMPIf PUBCOMP received, done
72No PUBREC receivedTimeoutResend PUBLISH
82No PUBCOMP receivedTimeoutResend PUBREL
92PUBCOMP receivedPUBCOMP receivedDone
💡 Execution stops when the final acknowledgement is received or no retry is needed.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6After Step 7After Step 8Final
Message SentNoYes (QoS0)Yes (QoS1)Yes (QoS1 resend)Yes (QoS1)Yes (QoS2)Yes (QoS2)Yes (QoS2 resend)Yes (QoS2 resend PUBREL)Yes (QoS2)
Acknowledgement ReceivedNoN/ANoNoYes (PUBACK)NoYes (PUBREC)NoYes (PUBCOMP)Yes
Retries0001100111
Key Moments - 3 Insights
Why does QoS 0 not wait for any acknowledgement?
Because QoS 0 means 'fire and forget'; the message is sent once without expecting any confirmation, as shown in execution_table step 1.
What happens if the PUBACK is not received in QoS 1?
The message is resent until PUBACK is received, as shown in execution_table steps 3 and 4 where a resend occurs after timeout.
Why does QoS 2 have two acknowledgement steps?
QoS 2 ensures exactly once delivery using a two-phase handshake: PUBREC and PUBCOMP, shown in execution_table steps 5-9.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does QoS 1 resend the message?
AStep 3
BStep 2
CStep 5
DStep 7
💡 Hint
Check the 'Action' and 'Result' columns for QoS 1 in execution_table rows.
According to variable_tracker, how many retries happen for QoS 2?
A0
B1
C2
D3
💡 Hint
Look at the 'Retries' row under 'After Step 7' and 'After Step 8' columns.
If QoS 0 sent a message, what is the acknowledgement status immediately after?
AAcknowledgement received
BWaiting for PUBACK
CNo acknowledgement expected
DWaiting for PUBREC
💡 Hint
Refer to execution_table step 1 and variable_tracker 'Acknowledgement Received' for QoS 0.
Concept Snapshot
QoS Levels in MQTT:
- QoS 0: Send once, no ack, possible loss
- QoS 1: Send, wait PUBACK, resend if no ack
- QoS 2: Two-phase ack (PUBREC, PUBCOMP), exactly once delivery
Each level increases delivery guarantee and network traffic
Full Transcript
This visual execution shows how MQTT QoS levels 0, 1, and 2 handle message delivery. QoS 0 sends the message once without waiting for acknowledgement. QoS 1 sends the message and waits for a PUBACK; if none arrives, it resends until acknowledged. QoS 2 uses a two-step handshake with PUBREC and PUBCOMP to ensure the message is delivered exactly once. The execution table traces each step, showing actions and acknowledgements. Variable tracking shows message sent status, acknowledgements received, and retry counts. Key moments clarify common confusions about acknowledgements and retries. The quiz tests understanding of when resends happen and acknowledgement expectations. This helps beginners see how MQTT ensures message delivery reliability with increasing levels of guarantee.

Practice

(1/5)
1. What does QoS level 0 mean in IoT messaging?
easy
A. The message is stored indefinitely until acknowledged.
B. The message is delivered at least once, with confirmation.
C. The message is delivered exactly once, with a handshake.
D. The message is delivered at most once, with no confirmation.

Solution

  1. Step 1: Understand QoS 0 delivery

    QoS 0 means the message is sent once without waiting for any acknowledgment.
  2. Step 2: Compare with other QoS levels

    QoS 1 and 2 involve confirmations; QoS 0 does not guarantee delivery.
  3. Final Answer:

    The message is delivered at most once, with no confirmation. -> Option D
  4. Quick Check:

    QoS 0 = no confirmation, at most once delivery [OK]
Hint: QoS 0 means no delivery guarantee, just send once [OK]
Common Mistakes:
  • Confusing QoS 0 with guaranteed delivery
  • Thinking QoS 0 waits for acknowledgment
  • Mixing QoS 0 with QoS 1 or 2 features
2. Which QoS level requires a four-step handshake to ensure message delivery?
easy
A. QoS 0
B. QoS 2
C. QoS 1
D. none of the above

Solution

  1. Step 1: Recall handshake details for QoS levels

    QoS 2 uses a four-step handshake to guarantee exactly once delivery.
  2. Step 2: Differentiate from other QoS levels

    QoS 0 has no handshake; QoS 1 uses a simpler acknowledgment.
  3. Final Answer:

    QoS 2 -> Option B
  4. Quick Check:

    Four-step handshake = QoS 2 [OK]
Hint: Four-step handshake means QoS 2 for exactly once delivery [OK]
Common Mistakes:
  • Confusing QoS 1's single acknowledgment with four-step handshake
  • Assuming QoS 0 has any handshake
  • Choosing 'none of the above' incorrectly
3. Given a device publishes a message with QoS 1, what is the expected behavior?
medium
A. The message is sent at least once, with acknowledgment.
B. The message is sent once without acknowledgment.
C. The message is sent exactly once, with a four-step handshake.
D. The message is queued indefinitely until delivered.

Solution

  1. Step 1: Understand QoS 1 delivery

    QoS 1 ensures the message is delivered at least once by requiring acknowledgment.
  2. Step 2: Compare with QoS 0 and 2

    QoS 0 sends once without acknowledgment; QoS 2 ensures exactly once with handshake.
  3. Final Answer:

    The message is sent at least once, with acknowledgment. -> Option A
  4. Quick Check:

    QoS 1 = at least once with ack [OK]
Hint: QoS 1 means message sent at least once, confirmed by ack [OK]
Common Mistakes:
  • Mixing QoS 1 with QoS 0's no acknowledgment
  • Confusing QoS 1 with QoS 2's exactly once guarantee
  • Assuming indefinite queuing for QoS 1
4. A developer sets QoS 2 but notices duplicate messages received. What is the likely cause?
medium
A. The handshake process was interrupted or not completed.
B. QoS 2 does not guarantee exactly once delivery.
C. QoS 0 was actually set by mistake.
D. The broker does not support QoS levels.

Solution

  1. Step 1: Understand QoS 2 guarantees

    QoS 2 guarantees exactly once delivery only if handshake completes successfully.
  2. Step 2: Analyze duplicate message cause

    If handshake is interrupted, duplicates can occur due to retries.
  3. Final Answer:

    The handshake process was interrupted or not completed. -> Option A
  4. Quick Check:

    Incomplete handshake causes duplicates in QoS 2 [OK]
Hint: Incomplete handshake causes duplicates in QoS 2 [OK]
Common Mistakes:
  • Believing QoS 2 never allows duplicates
  • Assuming wrong QoS level was set without checking
  • Ignoring broker capabilities
5. An IoT system must send critical sensor data exactly once without loss or duplication. Which QoS level should be used and why?
hard
A. QoS 0, because it is fastest and sufficient for critical data.
B. QoS 1, because it guarantees delivery but may duplicate messages.
C. QoS 2, because it guarantees exactly once delivery with handshake.
D. None, critical data should be sent manually.

Solution

  1. Step 1: Identify critical data requirements

    Critical data needs no loss and no duplication, so exactly once delivery is required.
  2. Step 2: Match QoS level to requirement

    QoS 2 provides exactly once delivery using a four-step handshake, ensuring no duplicates or loss.
  3. Final Answer:

    QoS 2, because it guarantees exactly once delivery with handshake. -> Option C
  4. Quick Check:

    Critical data needs QoS 2 for exactly once delivery [OK]
Hint: Critical data needs QoS 2 for no loss or duplicates [OK]
Common Mistakes:
  • Choosing QoS 0 for critical data due to speed
  • Confusing QoS 1's at least once with exactly once
  • Ignoring handshake importance
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard