0
0
IOT Protocolsdevops~6 mins

QoS levels (0, 1, 2) in IOT Protocols - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine sending important messages over a network where some might get lost or arrive multiple times. The challenge is to control how messages are delivered to make sure they reach safely and correctly without wasting resources.
Explanation
QoS Level 0: At Most Once
This level sends a message only once without asking for confirmation. If the message gets lost, it won't be resent. It is the fastest and uses the least resources but does not guarantee delivery.
QoS 0 means messages are sent once with no guarantee they arrive.
QoS Level 1: At Least Once
Here, the sender keeps sending the message until it gets an acknowledgment from the receiver. This ensures the message arrives at least once but might be received multiple times if acknowledgments are delayed.
QoS 1 guarantees delivery but may cause duplicate messages.
QoS Level 2: Exactly Once
This level uses a handshake process between sender and receiver to make sure the message is delivered only once. It is the safest but requires more communication and time.
QoS 2 ensures each message is received exactly once with no duplicates.
Real World Analogy

Imagine mailing letters with different levels of care: dropping a postcard in the mailbox without tracking, sending a registered letter that requires a signature, and sending a courier package that confirms delivery and prevents duplicates.

QoS Level 0: At Most Once → Dropping a postcard in the mailbox without tracking or confirmation
QoS Level 1: At Least Once → Sending a registered letter that requires a signature to confirm delivery
QoS Level 2: Exactly Once → Sending a courier package with a detailed delivery process ensuring no duplicates
Diagram
Diagram
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│Sender         │       │Network        │       │Receiver       │
├───────────────┤       ├───────────────┤       ├───────────────┤
│QoS 0: Send →─┐│──────▶│               │──────▶│ Receive once  │
│No ack needed ││       │               │       │or lost        │
├───────────────┤       │               │       ├───────────────┤
│QoS 1: Send →─┐│──────▶│               │       │Send ack ◀─────┤
│Wait for ack  ││◀──────│               │       │May receive    │
│Resend if no  ││       │               │       │duplicates    │
│ack          ││       │               │       ├───────────────┤
│QoS 2: Send →─┐│──────▶│               │       │Send ack 1 ◀───┤
│2-step handshake│      │               │       │Send ack 2 ◀───┤
│Ensures once  ││◀──────│               │       │Receive once   │
└───────────────┘       └───────────────┘       └───────────────┘
Diagram showing how messages flow from sender to receiver with different QoS levels and acknowledgments.
Key Facts
QoS 0Messages are sent once without acknowledgment and may be lost.
QoS 1Messages are sent until acknowledged, ensuring delivery but allowing duplicates.
QoS 2Messages are delivered exactly once using a two-step handshake.
AcknowledgmentA signal sent by the receiver to confirm message receipt.
Duplicate MessageA message received more than once due to retransmission.
Common Confusions
Believing QoS 0 guarantees message delivery.
Believing QoS 0 guarantees message delivery. QoS 0 does not guarantee delivery; messages can be lost without retries.
Assuming QoS 1 prevents duplicate messages.
Assuming QoS 1 prevents duplicate messages. QoS 1 ensures delivery but may cause duplicates if acknowledgments are delayed.
Thinking QoS 2 is always faster than other levels.
Thinking QoS 2 is always faster than other levels. QoS 2 is slower due to extra steps but ensures no duplicates and guaranteed delivery.
Summary
QoS levels control how messages are delivered to balance speed, reliability, and duplicates.
QoS 0 sends messages once without confirmation, risking loss.
QoS 1 ensures delivery but may cause duplicates, while QoS 2 guarantees exactly one delivery with more overhead.