Chapters

CoAP Exchange Reliability Contracts: Reference

Return to the parent chapter.

Related reference: CoAP message types.

A valve applies a request, but its acknowledgement is lost. The client sees silence. Should it send again, and what would that second packet prove?

CoAP, the Constrained Application Protocol, defines message exchange rules for constrained devices. The client sends a request; the server answers it. The payload carries application data such as a valve target. Follow one lost reply to separate message receipt, the reported result, and the physical action.

Separate the Exchange From the Valve Action

A client sends a Confirmable (CON) request to set a valve target to 30%. CON asks the receiver to acknowledge the message. The request has Message ID (MID) 4102 for message acknowledgement and duplicate detection, and Token 7a to match the peer’s response to this request. These are example identifiers, not permanent command identities. The Code states the requested method or the reported result.

The valve applies the target and sends an Acknowledgment (ACK) with MID 4102. Assume the ACK also carries the operation response and Token 7a. The ACK is lost. After its timer expires, the client retransmits the original CON with MID 4102 and Token 7a. The server recognizes that message from that client as a duplicate and reuses its acknowledgement rather than treating the packet as a new action.

Setting a target describes a desired state. Repeating a dosing command could instead add another dose. Such an operation is non-idempotent: repetition can add an effect. Message duplicate handling protects a bounded exchange. An application command identifier with a stored outcome can protect a later attempt after that state expires, if the record survives the required retry period.

In Figure 2, compare the request and return arrows. A Non-confirmable (NON) message creates no ACK duty and has no CoAP message retransmission. A NON request can still receive an application response. A Reset (RST) signals that the receiver lacks the context to process the message; it is not a successful operation result.

Use Figure 1 to follow MID between a CON and its ACK, then Token between a request and its response. An ACK can carry the response, or it can be empty while the server prepares a later response. That distinction decides whether the client has a result or only message-receipt evidence.

Start With the Lost ACK

Prove a Retry Does Not Repeat the Action

For the valve trace, predict before checking the logs: after the lost ACK, the same MID should appear again. At the server, look for duplicate detection and the recorded acknowledgement. Compare that decision with the valve action count. A packet trace alone cannot prove how many times the hardware moved.

Keep packet times, peer addresses, Type, Code, MID, Token, server decisions, and action evidence together. If no reply arrives before the client gives up, the outcome is unknown to the client: the request may have been lost, or the valve may have acted and every reply been lost. A timeout does not prove non-execution.

Transfer the reasoning later to a slow sensor. Once its empty ACK arrives, request retransmission stops, but the client still needs a response with the original Token. Decide what that next packet must contain before reading the answer.

Learning Objectives

After this page, you should 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.

Why This Contract Comes After Message Types

CoAP Message Types introduces the four types. Here, use them to diagnose the valve trace: Type and MID govern acknowledgement and duplicate handling; Code and Token express the request or result and connect a response to its request.

Keep three questions separate: did the peer receive this message, what result did it report, and what happened at the device? A delayed result, lost ACK, or reboot can make those answers differ.

Overview: Four Message Types Living in Two Layers

In the valve trace, the messaging layer handles receipt and duplicates using Type and the 16-bit MID. The request/response layer uses Code for the method or result and Token for correlation with the request. A CON can carry a request or a response: Type does not identify its application meaning.

CON retransmission follows a timer if no ACK or RST arrives. NON creates no ACK duty and no CoAP message retransmission. An ACK echoes the CON MID. RST reports missing context, such as an unrecognized response after a reboot.

Read both layers: Type=CON, Code=0.01 is a confirmable GET request; Type=ACK, Code=2.05 carries a Content response in an ACK. Type=ACK, Code=0.00 is an empty ACK: it stops retransmission but carries no operation result or Token. Type=RST, Code=0.00 is an empty Reset. Do not infer valve success from an empty ACK.

For every packet, ask what Type requires and what Code reports. CON and NON can carry requests or responses. ACK and RST are CoAP messaging signals. A missing NON sample may be acceptable when a later reading replaces it; a missing command result still needs an application policy.

Simulation · interactive

CoAP Message Builder

Explore how the system behaves.

Inspect Figure 2 for the return packets each pattern requires. Predict which packet stops a retransmission and which carries the operation result.

The top row of Figure 2 contrasts Confirmable / Reliable, where a CON Request receives an ACK Response, with Non-Confirmable / Fire-and-forget, where the NON Message has no return arrow. The lower Piggybacked / Inline response exchange carries ACK 2.05 + Data in one return packet. By contrast, Separate / Deferred response first sends ACK (empty), later delivers CON 2.05 + Data, and requires a final ACK. Those sequences keep delivery timing separate from the GET or PUT meaning assigned at the request/response layer.

Confirmable (CON)

Requests an ACK and retries on timeout until acknowledged, reset, or abandoned. Choose it for message-receipt evidence, then inspect the operation result separately.

Non-confirmable (NON)

No ACK duty and no CoAP message retransmission. Replaceable readings can use it when the application tolerates gaps.

Acknowledgment (ACK)

Confirms exactly one CON by echoing its Message ID. It may be empty, or it may piggyback the response.

Reset (RST)

Signals that a received message could not be processed for lack of context. It also answers a CoAP ping (an empty CON).

An Observe registration is stored subscription state for resource updates. A notification is one such update. In the next case, the rebooted client no longer recognizes that state.

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

Return to MID 4102. Suppose its first timeout is T = 2 s. With no ACK or RST, the client waits 2 s and retransmits, waits 4 s and retransmits again, then waits 8 s before the third retry. That retry is 14 s after the initial send. The intervals double; they are not all measured from the initial send.

For the RFC 7252 default schedule, use ACK_TIMEOUT = 2 s, ACK_RANDOM_FACTOR = 1.5, and MAX_RETRANSMIT = 4. Choose the initial timeout T in the 2–3 s window, then double that chosen timeout after each retransmission. The maximum default first-to-last-send span is MAX_TRANSMIT_SPAN = 45 s; the maximum default wait before abandonment is MAX_TRANSMIT_WAIT = 93 s. These are upper bounds, not exact durations for every trace.

Worked Example: Valve Command vs Temperature Stream

The valve uses PUT /actuators/valve to request its target state. CON lets the controller check receipt, but a lost response leaves the reported outcome unknown. In this design, readings from /sensors/temp arrive every 10 seconds as NON, and the application accepts gaps because later readings replace earlier ones. That loss policy fits this stream; it does not establish a safe valve fallback deadline.

Simulation · interactive

ACK/NACK Timing Visualizer

Explore how the system behaves.

Attempt
Default timer rule
Wait or elapsed bound
Outcome if ACK still lost
Initial send
Choose T in [ACK_TIMEOUT, ACK_TIMEOUT × ACK_RANDOM_FACTOR]
T: 2 to 3 s
Retransmit #1
Retransmit 1
timeout doubles
2T: 4 to 6 s
Retransmit #2
Retransmit 2
timeout doubles
4T: 8 to 12 s
Retransmit #3
Retransmit 3
Wait 8T, then retransmit #4
16 to 24 s; last send at 15T, at most 45 s
After #4, wait 16T; abandon at 31T, at most 93 s

Practitioner Checklist

Record the initial timeout, retry limit, application deadline, and local fallback. Let CoAP manage this message’s retransmissions; a new application attempt needs a repeat-safety policy. NSTART limits outstanding interactions with a peer and defaults to 1. An unacknowledged CON occupies that limit. A request counts as outstanding while neither its response nor its acknowledgement has arrived. An empty ACK therefore ends that request’s outstanding interaction for NSTART, even though its separate response remains pending. For a CoAP ping, send an empty CON and expect RST: that checks peer reachability, not valve state.

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

If the valve result is ready promptly, a piggybacked response carries it inside the ACK. MID 4102 acknowledges the request message, and Token 7a identifies its response. Inspect the response Code for the reported result. For a GET, 2.05 Content reports returned content; it is not a generic valve-write success code.

Transfer the rule to a slow sensor GET. The server sends an empty ACK with the request MID and Code 0.00. Request retransmission stops, but sampling is still pending. A later separate response is a new CON or NON with its own MID and the original request Token. If it is CON, the client ACKs that new MID. The empty ACK contains no Token; correlation belongs to the later response.

ServerClientServerClientPiggybacked (answer ready now)Separate (server needs time)CON GET (MID, Token)ACK 2.05 Content (same MID, Token)CON GET (MID, Token)ACK (empty)CON 2.05 Content (new MID, same Token)ACK

The difference between a piggybacked and separate response becomes clear when Figure 1 is read with Message ID and Token as two distinct threads.

In Figure 1, first follow the Message ID that pairs a CON with its ACK. Then follow the Token that pairs the application response with the original request. 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.

The valve server needs duplicate suppression: recognize a recent message by source endpoint and MID and reuse its acknowledgement rather than repeat a non-idempotent effect. Record the implementation’s retention period and MID reuse policy; this bounded state is not permanent command history. An idempotent operation has the same intended effect when repeated, such as setting the same target. Appending an entry or adding a dose may instead need an application command ID and a stored result that survives the required retry period.

Piggybacked

ACK carries the response. Same Message ID as the request, Token matches. Used when the answer is immediate.

Separate

Empty ACK stops request retransmission. A new CON/NON carries the result with the original Token; match it in the peer’s request context.

Message ID

A 16-bit field for duplicate detection and matching ACK to CON or RST to CON/NON. It is not a permanent application command ID.

Dedup window

Retain duplicate state for the exchange policy and reuse the acknowledgement for a recognized duplicate. Keep application replay protection for longer-lived side effects.

Release Checklist

Before signing off a CoAP message-flow design, verify that:

  • Each interaction names the Type, Code, Message ID, Token, and CON/NON policy.
  • 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.
  • Handling of unrecognized responses, lost registration state, and malformed messages is defined by message type and failure; RST is not a general application error response.
  • The energy budget explains which traffic is allowed to be NON and what loss rate the application tolerates.

See Also

Review the message types before the field layout, since the exchange contract depends on both type and matching fields.

Next

After you can read a message exchange at both layers, continue with CoAP Message Format to inspect the exact bits and option fields carried in each datagram.

Detail notes moved from the chapter

Historical protected source blocks retained for the chapter preservation check.

The difference between a piggybacked and separate response becomes clear when Figure 1 is read with Message ID and Token as two distinct threads.

Follow the CON-to-ACK pair, then the empty ACK and later result in the separate-response sequence. A delayed result answers the request in a new message exchange.
The Message ID ties an ACK to its CON at the messaging layer; the Token ties a response to its request at the request/response layer, which is what makes separate responses possible.
  1. Broker Bex: Bex brings a request card with two distinct shape tokens to a sleepy sensor counter.

    A slow request arrives with a message number and token.

  2. Broker Bex, a green device character, holds a white card with a blue circle at a service counter. A white robot stands behind the counter beside empty trays; no message text or number is visible.

    An empty ACK stops request retransmission; it does not report the result.

  3. Broker Bex: Bex waits beside the working sensor while holding the other matching shape token.

    The sensor works. Bex keeps the request token safe.

  4. Broker Bex: A fresh envelope with a new number shape carries the result and the original request-token shape.

    The result returns in a new message with the same token.

  5. Broker Bex, a green device character, holds a white card marked with blue and purple shapes at a service counter while a white robot offers a small paper slip. The illustration shows the handover without protocol labels.

    If the result is CON, the client ACKs its new Message ID.

The slow-server sequence separates receipt from result: an empty ACK comes first, then a new response keeps the request Token. The shapes illustrate the distinction; use packet fields to verify it.

In Figure 1, first follow the Message ID that pairs a CON with its ACK. Then follow the Token that pairs the application response with the original request. 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.

The valve server needs duplicate suppression: recognize a recent message by source endpoint and MID and reuse its acknowledgement rather than repeat a non-idempotent effect. Record the implementation’s retention period and MID reuse policy; this bounded state is not permanent command history. An idempotent operation has the same intended effect when repeated, such as setting the same target. Appending an entry or adding a dose may instead need an application command ID and a stored result that survives the required retry period.

Piggybacked

ACK carries the response. Same Message ID as the request, Token matches. Used when the answer is immediate.

Separate

Empty ACK stops request retransmission. A new CON/NON carries the result with the original Token; match it in the peer’s request context.

Message ID

A 16-bit field for duplicate detection and matching ACK to CON or RST to CON/NON. It is not a permanent application command ID.

Dedup window

Retain duplicate state for the exchange policy and reuse the acknowledgement for a recognized duplicate. Keep application replay protection for longer-lived side effects.

CON has a return ACK arrow; NON has no ACK arrow. Below, a result inside an ACK contrasts with an empty ACK followed by a CON result and final ACK.
Compare the CON acknowledgement and NON send, then see why a delayed result needs a later response rather than the first ACK.

Hi, I’m Broker Bex. What do you need?

Find help

Let’s find what you need

Find a lesson or return to your module guide.

Give feedback

Help improve this chapter

Tell us what helped or what needs fixing.

Tips

Try a small next step

A few ways to get more from this chapter.

Ask AI

Continue the conversation

Take the conversation further with your preferred assistant.

AI help is available in supported modules when enabled in Settings.

No live person answers on independent study. Feedback does not promise a personal reply.

For welfare or safety concerns, follow your school’s procedures outside IoTClass.