CoAP · Study deck

CoAP Exchange Reliability Contracts

A battery valve sends a CoAP request over a lossy radio and waits for an acknowledgement that may never arrive.

Broker Bex is your guide for this deck.

messagereliability
Broker Bex, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Separate CoAP message-layer type from request/response Code and Token semantics in a packet trace.
  • Set CON/NON policy and document ACK timeout, randomization, backoff, and retransmission evidence.
  • Distinguish piggybacked ACK-plus-response exchanges from separate responses that use a new Message ID.
  • Diagnose duplicate suppression, Message ID reuse, Token correlation, and RST paths after context loss.
iotclass.org

Major section

Separate the Exchange From the Valve Action

A non-confirmable message does not create that acknowledgement duty.

  • The message ID supports duplicate detection for the message exchange.
  • The token lets a client match a response to its request.
  • Neither identifier alone proves that a physical command is safe to repeat.
CoAP reliable, fire-and-forget, piggybacked, and separate exchange patterns.
CoAP reliable, fire-and-forget, piggybacked, and separate exchange patterns.
iotclass.org

Major section

Separate the Exchange From the Valve Action (continued)

The valve applies the target and sends an acknowledgement, but that packet is lost.

  • Duplicate handling should return the prior exchange result without applying a second non-idempotent action.
  • A command identifier in the application payload gives longer-lived protection when protocol duplicate state expires.
  • If the first wait is 2 s and each retry doubles it, waits before three retries are 2 s, 4 s, and 8 s, totalling 14 s.
iotclass.org

Major section

Start With the Lost ACK

A protocol means agreed rules and message order for communication.

  • Constrained Application Protocol (CoAP) is a web-style method made for small devices and limited networks.
  • A Confirmable command can be delivered, executed, and still look failed if the ACK disappears on the way back.
  • The client retries; the server must recognize the duplicate; the response still needs to match the original request instead of running the command twice.
iotclass.org

Major section

Overview: Four Message Types Living in Two Layers

The messaging layer handles the datagram itself and uses four message types plus a 16-bit Message ID.

  • The message type is orthogonal to whether a datagram carries a request or a response: a single message is both a type (CON/NON/ACK/RST) and, usually, a request or response.

Key terms

Elicits an ACK and
Elicits an ACK and is retransmitted on timeout.
CoAP reliable, fire-and-forget, piggybacked, and separate exchange patterns.
CoAP reliable, fire-and-forget, piggybacked, and separate exchange patterns.
iotclass.org

Major section

Overview: Four Message Types Living in Two Layers (continued)

Confirmable (CON) Elicits an ACK and is retransmitted on timeout.

  • Confirmable (CON) asks for reliability: the sender expects an acknowledgment and will retransmit if none arrives.
  • A useful packet-trace habit is to name both layers for every datagram.
  • It may be empty, or it may piggyback the response.
iotclass.org

Major section

Practitioner: Reliability Is a Per-Message Decision With Named Timers

When you mark a message CON, you inherit RFC 7252's retransmission machinery, and its constants are worth knowing by name.

  • The first retransmission timeout is a random value between ACK_TIMEOUT (default 2 s) and ACK_TIMEOUT × ACK_RANDOM_FACTOR (default 1.5, so up to 3 s).
  • That yields a worst-case window of roughly 45 seconds ( MAX_TRANSMIT_SPAN ) before the sender gives up on that Message ID.
  • Approx. Wait before retry.

Key terms

If the valve ACK
If the valve ACK is lost, the timeline below plays out; the temperature NON simply relies on the next sample.
iotclass.org

Major section

Practitioner: Reliability Is a Per-Message Decision With Named Timers (continued)

By default NSTART = 1, meaning an endpoint keeps only one CON exchange outstanding to a given destination at a time.

  • If you need concurrency, you either raise NSTART carefully or use NON for the bulk traffic.
  • If the valve ACK is lost, the timeline below plays out; the temperature NON simply relies on the next sample.
  • Account for NSTART = 1 as well; confirmable writes to one peer serialize, so the latency budget must cover the queue.
iotclass.org

Major section

Under the Hood: Piggybacked vs Separate Responses, and Duplicate Suppression

A server has two ways to answer a Confirmable request.

  • The ACK reuses the request's Message ID, and the Token matches the request's Token.
  • If that later message is CON, the client ACKs it in turn.
  • Because a CON can be retransmitted, a server may receive the same message twice.

Key terms

Used when the answer
Used when the answer is immediate.

Why it matters

The client recognizes it as the answer because the Token matches the original request.

CoAP message exchange showing header, token, options, and payload fields carried between client and server.
CoAP message exchange showing header, token, options, and payload fields carried between client and server.
iotclass.org

Major section

Under the Hood: Piggybacked vs Separate Responses, and Duplicate Suppression (continued)

A ready response can ride inside the ACK; a delayed response uses a new message exchange but retains the Token.

  • This separation also explains why duplicate suppression is keyed at the message layer while application correlation survives across exchanges.
  • Piggybacked ACK carries the response.
  • Used when the answer is immediate.
iotclass.org

Major section

Under the Hood: Piggybacked vs Separate Responses, and Duplicate Suppression (continued)

A duplicate CON must not be acted on twice; instead the server resends the cached ACK.

  • This matters most for non-idempotent operations — a duplicated POST that appended a log entry, or a relative counter increment, would be wrong if processed twice.
  • Same Message ID as the request, Token matches.
  • Separate Empty ACK stops retransmission, then a new CON/NON carries the response, correlated only by Token.
iotclass.org

Major section

Release Checklist

ACK timeout, ACK random factor, maximum retransmits, and any NSTART change are recorded with their rationale.

  • Piggybacked and separate response cases are distinguished, including when an empty ACK is sent.
  • Duplicate cache lifetime, Message ID reuse policy, and non-idempotent operation handling are explicit.
  • RST behavior is defined for unknown tokens, lost Observe state, rebooted endpoints, and malformed messages.
iotclass.org

Deck summary

Key takeaways

A non-confirmable message does not create that acknowledgement duty.

  • The valve applies the target and sends an acknowledgement, but that packet is lost.
  • A protocol means agreed rules and message order for communication.
  • The messaging layer handles the datagram itself and uses four message types plus a 16-bit Message ID.
  • Confirmable (CON) Elicits an ACK and is retransmitted on timeout.
iotclass.org

Retrieval practice

Recall check 1 of 3

Broker Bex says: answer from memory, then check your reasoning.

Q1A constrained node reboots and then receives a Confirmable notification for an Observe registration it no longer remembers. Which message type should it send back?

ARST, because it received the message but has lost the context needed to process it.
BACK, because the notification arrived intact and the sender needs confirmation of delivery.
CA new CON request, because the node should re-register the resource first.
DNON, because the node wants to avoid retry traffic while it recovers from reboot.
Show answer

Answer: A RST means 'received but not processable here'; it is exactly how a node cancels an exchange whose context it lost, such as after a reboot.

iotclass.org

Retrieval practice

Recall check 2 of 3

Broker Bex says: answer from memory, then check your reasoning.

Q2A device sends a Confirmable PUT and receives no ACK. Roughly how does CoAP's default retransmission behave before it declares failure?

AIt retransmits up to MAX_RETRANSMIT
BIt retransmits forever at a fixed 1-second interval until an ACK finally arrives.
CIt immediately switches the message to NON and stops caring about delivery.
DIt sends the retransmissions in parallel to speed up delivery.
Show answer

Answer: A ACK_TIMEOUT (2 s) times ACK_RANDOM_FACTOR (1.5) sets the first random window, then binary exponential backoff runs for up to MAX_RETRANSMIT (default 4) retransmissions. With default constants, MAX_TRANSMIT_SPAN is about 45 seconds before failure is reported.

iotclass.org

Retrieval practice

Recall check 3 of 3

Broker Bex says: answer from memory, then check your reasoning.

Q3A CoAP server needs several seconds to sample a slow sensor before it can answer a Confirmable GET. What is the correct exchange pattern?

ASend nothing until the reading is ready, then piggyback the response on the eventual ACK.
BSend a RST to tell the client to try again after the sensor is ready.
CReuse the request's Message ID on the delayed response so the client can match it.
DReturn an empty ACK immediately to stop retransmission.
Show answer

Answer: D The empty ACK confirms receipt so the client stops retransmitting.

iotclass.org

Print reference

Answers

Answer key.

  1. A · RST means 'received but not processable here'; it is exactly how a node cancels an exchange whose context it lost, such as after a reboot.
  2. A · ACK_TIMEOUT (2 s) times ACK_RANDOM_FACTOR (1.5) sets the first random window, then binary exponential backoff runs for up to MAX_RETRANSMIT (default 4) retransmissions. With default constants, MAX_TRANSMIT_SPAN is about 45 seconds before failure is reported.
  3. D · The empty ACK confirms receipt so the client stops retransmitting.
iotclass.org