Chapters

CoAP Message Exchanges: Reference

Return to the parent chapter.

In 60 Seconds

Match the Envelope to the Consequence

A freezer sensor sends a routine temperature sample every 30 seconds and a rare door alarm. If the application can use the next sample after a loss, choose Non-Confirmable (NON): no CoAP acknowledgment is expected. For the alarm, choose Confirmable (CON): request an acknowledgment and retry if it is missing, within a retry limit. If delivery remains unconfirmed, the application needs an escalation rule.

An Acknowledgment (ACK) confirms receipt of a CON message. It can also carry the application response, but an empty ACK contains no result. Reset (RST) rejects a message the receiver lacks context to process. A missing resource instead gets an application error response.

Your task is to choose delivery behavior and then diagnose a trace: which message was received, which result is ready, and what remains unknown? A payload is the content inside a message; receipt alone does not prove that its reading is true or that an actuator moved.

Start With the Delivery Choice

Work the freezer case before choosing a message type. A lost routine sample can leave an older value on the display until another sample arrives. Under an explicit tolerance for that gap, send the routine sample as NON. A door alarm cannot be replaced by the next temperature sample, so send it as CON and define what happens if retries end without confirmation.

Now lose only the alarm’s ACK. The sender cannot distinguish a lost alarm from a lost ACK, so it may retransmit the same message. The receiver needs duplicate handling; the application must not infer a second door event from that retry. Even a valid ACK establishes message receipt, not the alarm’s physical resolution.

Phoebe’s Field Notes: The Sleep Current Hidden Behind CON and NON

The mathematical gist. NON uses 0.0136 mAh/day of active charge and CON uses 0.218 mAh/day, but practical lifetime must add the always-on current: Qday=Qactive+24Isleep/1000Q_{day}=Q_{active}+24I_{sleep}/1000. With about 13.75 µA asleep, the chapter’s 1000 mAh cell lasts about 8.0 years on NON and 5.0 years on CON. The separate 8 mA transmit pulse through 0.5 ohm sags only 4.0 mV, so the charge comparison is plausible for this fresh-cell case.

Math Bridge · guided foundationsWhere does an eight-year NON lifetime really come from?Let Eddie add active charge, sleep current, energy, and pulse sag.

Learning Objectives

By the end of this chapter, you will be able to:

  • Distinguish the four CoAP message types (CON, NON, ACK, RST) and their roles in the protocol.
  • Select the appropriate message type based on reliability requirements and battery constraints.
  • Explain piggyback vs separate response patterns and when each is used.
  • Calculate the energy trade-off between CON and NON messages for battery-powered devices.
Chapter Roadmap

Use this path through the protocol:

  1. First choose CON or NON by asking whether the next reading can replace this one.
  2. Then price that choice with 20-byte readings, 53-byte packets, 50 ms ACK waits, and the roughly 15.52x radio-charge ratio.
  3. Next separate ACK/RST protocol signals from application errors.
  4. Finally compare piggyback, separate response, retransmission, and quiz scenarios.

Checkpoints recap the decision rules. Calculation audits and simulators are deeper support, optional on a first pass.

Key Concepts
  • CON: asks for acknowledgment and supports bounded retransmission; delivery can still fail.
  • NON: has no CoAP acknowledgment or message-layer retry. A NON request may still receive an application response.
  • ACK: acknowledges a CON by its Message ID; it can contain an application response or be empty.
  • RST: rejects a message whose context the receiver cannot use; it is not an ordinary resource error.
  • Message ID: identifies a message for duplicate detection and ACK/RST matching at the endpoint.
  • Token: associates an application response with its request, including when the response arrives separately.

For Beginners: CoAP Message Types

For the freezer alarm, ask two different questions: “Did the receiver get this message?” and “What did the application report?” A matching ACK answers the first. A response code and any payload answer the second. An empty ACK leaves the second question open.

Four Ways to Send a Message

Trace the same freezer exchange through four outcomes. Send the replaceable reading as NON and expect no ACK. Send the alarm as CON and wait for a matching ACK. If the receiver can return a result promptly, that ACK can carry it. If a receiver has lost the context for an incoming CON response, it returns RST instead.

These are message roles, not four interchangeable sending policies. In particular, RST does not mean “the requested resource is missing”; that is an application response such as 4.04 Not Found.

Continue: CoAP Message Reliability and Exchange Contracts

The main chapter below stays focused on CoAP message types, energy tradeoffs, and exchange patterns. For the deeper contract behind CON/NON/ACK/RST layering, named timers, ACK timeout/backoff, Message ID versus Token roles, piggybacked versus separate responses, duplicate suppression, and reset handling, continue to CoAP Message Reliability and Exchange Contracts.

CoAP Message Types

Inspect the figure in the parent chapter to choose CON or NON from the consequence of loss and then place ACK and RST around that sender choice.

Read the figure in the parent chapter from the two sending choices into their outcomes. CON starts a reliability exchange and waits for a matching ACK, while NON spends no acknowledgment traffic and accepts possible loss. ACK is therefore a response type, not a competing delivery policy, and RST reports that a message reached a receiver that could not process its protocol state. The next two sections trace the sender branches separately.

Confirmable (CON)

Bounded delivery effort: CON requests acknowledgment; it cannot ensure arrival.

Use when:

  • The sender needs evidence of message receipt.
  • Loss requires retry and an application fallback.
  • A command or update needs this policy because of its consequences, not merely its method name.

To see what “requires acknowledgment” means on the wire, trace one request through the figure in the parent chapter. Keep the Message ID distinct from the Token while following the normal and timeout paths.

In the figure in the parent chapter, begin with the CON GET and its Message ID 0x1234; the timer starts as that datagram leaves. A matching ACK stops retransmission, and the Token T7 associates returned content with the request. If the ACK is absent, the client retransmits the same CON with backoff rather than inventing a new operation. That extra exchange buys bounded delivery effort for the critical cases above.

Non-Confirmable (NON)

Unacknowledged delivery: NON has no CoAP ACK or message-layer retry.

Use when:

  • Frequent sensor readings.
  • Data loss acceptable.
  • Minimizing network traffic.
  • Battery conservation critical.

When a newer reading makes an older one disposable, the figure in the parent chapter shows the smaller contract. Look for the deliberate absence of both an ACK timer and a retransmission loop.

Follow the figure in the parent chapter from the status datagram to the server. If it arrives, the server processes it; if it disappears, neither endpoint opens a reliability exchange, and the next reading becomes the current state. NON reduces traffic because it removes recovery, not because UDP somehow became reliable. That fits the freezer’s replaceable telemetry under the stated loss tolerance. Its one-off alarm needs CON plus a fallback if confirmation never arrives.

CON vs NON: The Battery Life Trade-off

For the freezer sample, compare the extra receive time before claiming a battery saving. The model below assumes the radio listens at 5 mA for 50 ms while waiting for a CON acknowledgment. NON omits that modeled wait. This is a device assumption, not CoAP’s retransmission timeout.

CON can also incur retransmission costs. NON avoids CoAP acknowledgment traffic, but sensing, sleep current, link-layer acknowledgments, and application responses can still consume charge. Choose the acceptable loss behavior first, then measure the device’s current profile.

Bex guides the message review.Checkpoint: CON or NON
  • For the freezer alarm, choose CON because receipt must be confirmed; the method name alone does not choose delivery behavior.
  • NON fits frequent sensor readings where loss is acceptable and battery conservation is critical.
  • Battery life needs a full device-current budget; the message type alone does not determine it.

Worked Example: CON vs NON Energy Budget for Cold Chain Monitoring

Scenario (assumed design values, not measured hardware): A pharmaceutical warehouse uses 200 CoAP sensors monitoring freezer temperatures. Each sensor sends a 20-byte reading every 30 seconds. Sensors use 802.15.4 radios (250 Kbps) with 8 mA TX, 5 mA RX current at 3.0V. Assume a usable battery capacity of 1,000 mAh; this is a budget input, not a cell specification.

NON radio charge per transmission:

  • TX: 20-byte payload + 4-byte CoAP header + 1-byte payload marker (0xFF, required for a nonempty payload by RFC 7252 §3) + 8-byte UDP + assumed 20-byte compressed IPv6 header = 53 bytes. Assume zero Token bytes and no options; this illustrative 6LoWPAN case excludes 802.15.4 framing. A resource-addressed request may need additional option bytes.
  • TX time: 53 x 8 / 250,000 = 1.696 ms at 8 mA = 0.013568 mA·s.
  • Radio startup: ~0.5 ms at 8 mA = 0.004 mA·s.
  • Total per NON: 0.017568 mA·s.
Putting Numbers to It: Energy Cost Formula for CON vs NON

Current multiplied by time gives charge, QQ, in mA·s here. Energy is VQVQ at fixed voltage, so charge and energy have the same ratio in this 3.0 V model:

Qtotal=QTX+QRX+QstartupQ_{\text{total}} = Q_{\text{TX}} + Q_{\text{RX}} + Q_{\text{startup}}

For NON messages in this model (no receive wait or application response included):

QNON=ITX⋅tTX+Istartup⋅tstartupQ_{\text{NON}} = I_{\text{TX}} \cdot t_{\text{TX}} + I_{\text{startup}} \cdot t_{\text{startup}}

For CON messages (with ACK wait):

QCON=QNON+IRX⋅tACK_wait+IRX⋅tACK_RXQ_{\text{CON}} = Q_{\text{NON}} + I_{\text{RX}} \cdot t_{\text{ACK\_wait}} + I_{\text{RX}} \cdot t_{\text{ACK\_RX}}

Where ITX=8 mAI_{\text{TX}} = 8\text{ mA}, IRX=5 mAI_{\text{RX}} = 5\text{ mA} at V=3.0 VV = 3.0\text{ V} for 802.15.4.

For a 32-byte ACK under the same simplified header assumptions, receive time is 32×8/250000=1.02432\times8/250000=1.024 ms. The added charge is 5×(0.050+0.001024)=0.255125\times(0.050+0.001024)=0.25512 mA·s; adding NON’s 0.017568 gives 0.272688 mA·s. The ratio is:

QCONQNON=0.2726880.017568≈15.52×\frac{Q_{\text{CON}}}{Q_{\text{NON}}} = \frac{0.272688}{0.017568} \approx 15.52\times

This approximately 15.52× ratio applies only to the modeled radio energy per exchange with a 50 ms listening wait. Battery-life impact also depends on sleep current, sensing, retries, and other device work.

ACK Wait Energy Calculation Audit

At an assumed independent 5% loss per NON reading, 2,880 readings per day gives 144 expected losses. The next sample is sent 30 seconds later, but it too can be lost. Separately, if each complete CON attempt has a 5% chance of remaining unacknowledged, two independent attempts leave 0.052=0.25%0.05^2=0.25\% unconfirmed. A datagram loss rate alone does not establish that exchange failure probability. Decision: use NON for routine 30-second temperature readings if occasional loss is acceptable, and CON for rare threshold alerts (~2 per day) such as “Temperature exceeded -18C”. CON improves the chance of delivery but cannot guarantee an alert arrives; use an application-level escalation if missed alerts are unacceptable.

Maths · guided foundations

ACK Wait Energy Calculation Audit

Check the quantities and assumptions.

Bex guides the message review.Checkpoint: Energy Budget
  • The illustrative packet is 53 bytes: 20 payload + 4 CoAP + 1 payload marker + 8 UDP + an assumed 20-byte compressed IPv6 header. Token length is zero, options are absent, and 802.15.4 framing is excluded; addressing a resource may add option bytes.
  • At 250 Kbps, it takes 1.696 ms to transmit; with startup, NON costs 0.017568 mA·s.
  • CON adds the 50 ms ACK wait and 32-byte ACK receive, reaching 0.272688 mA·s, about 15.52x NON.

Interactive: CoAP Message Energy Calculator

Predict the effect of increasing the receive wait, then compare the calculator’s outputs. These are simplified estimates, not measured battery lifetimes: the model omits parts of the device budget, and its receive-wait control is not the CoAP retry timer. The protected calculator retains a 52-byte packet model that omits the required one-byte payload marker. At the worked-example settings it therefore gives 0.017312 mA·s for NON and 0.272432 mA·s for CON (about 15.74x), rather than the corrected 53-byte calculation above. Its outputs labeled energy are charge; its battery-percentage display is ten times too large, and its battery-life tip is not supported by a full device budget.

Acknowledgment (ACK)

ACKs cost power, but their meaning is narrow: they confirm CON receipt. Application success still depends on the response code they carry.

Confirms receipt of confirmable message:

  • May include response (piggyback).
  • Or just acknowledgment (response comes separately).

Reset (RST)

RST is a message-layer rejection, not an application error shortcut. Send it when a datagram is syntactically recognisable but the endpoint lacks the exchange context needed to process it—for example, a rebooted node receives a confirmable Observe notification it no longer recognises. An empty CON used as a ping can produce RST. A new Message ID alone is not grounds for rejection: a valid new request normally has one. An unexpected ACK is silently ignored. A valid GET for a missing resource can receive an immediate ACK with 4.04 Not Found, and temporary server unavailability belongs in a 5.03 response; those application outcomes must not be collapsed into reset.

Bex guides the message review.Checkpoint: ACK and RST Semantics
  • ACK confirms a valid CON and can piggyback a normal response such as 4.04 Not Found.
  • RST rejects unusable message context; an unrelated ACK is ignored, and an ordinary missing resource gets an application response.
  • Ignoring CON causes client retries up to MAX_RETRANSMIT.

Message Exchange Patterns

After ACK and RST, choose response timing. Fast work can ride inside ACK; slow work needs an empty ACK first.

Piggyback Response

When the representation is already available, the server can combine transport acknowledgment and application response. the figure in the parent chapter shows how one packet performs both jobs without confusing their identifiers.

Read the figure in the parent chapter as a single round trip. The ACK repeats Message ID 0x44A2, which stops retransmission of that CON, while Token T9 tells the client which request owns the 2.05 Content payload. Piggybacking is efficient because the response was ready inside the acknowledgment window; it is not a promise that every server operation completes that quickly.

Separate Response

If producing the representation takes longer than the acknowledgment window, the two jobs must separate. Inspect the sequence diagram in the figure in the parent chapter to trace that split for an eight-second diagnostic operation.

Reading the sequence diagram in the figure in the parent chapter from top to bottom, the empty ACK first repeats Message ID 0x6A10 and stops request retransmissions without pretending the result is ready. After the diagnostic work, the sensor sends a new CON with a new Message ID but the original Token T7; that token reconnects the delayed payload to the request. The gateway then acknowledges the response’s Message ID, completing two messaging exchanges around one request-response operation.

Interactive: CoAP Retransmission Timeline

RFC 7252 §4.2 selects one randomized initial wait and doubles that wait after each retransmission. MAX_RETRANSMIT counts retries after the initial send. With ACK_TIMEOUT = 2 seconds, random factor = 1, and four retries, predict the sends if no ACK or RST arrives: the initial send is at 0 seconds, retries are at 2, 6, 14, and 30 seconds, and failure is declared at 62 seconds after the final 32-second acknowledgment wait.

The retained timeline below differs from that algorithm: it draws a fresh random multiplier for every retry instead of doubling one initially selected wait. Its “until final timeout” value stops at the last retransmission and omits the final acknowledgment wait. RFC 7252 §4.8.2 distinguishes MAX_TRANSMIT_SPAN (through the last retransmission) from MAX_TRANSMIT_WAIT (through the final wait); in the factor-1 example these are 30 and 62 seconds. Set the random factor to 1 to compare the displayed sends with the correct prediction above, but add the final wait yourself. The display’s mA·s figures are charge, use a rounded legacy per-attempt value, and do not model the full retry listening budget or battery life.

Quick Review: Match & Sequence

Use the freezer case to match each role to its consequence. Then order a single lost-ACK path; do not combine the successful-ACK branch with a retry branch.

Knowledge check · self-test

Knowledge check

Test your understanding.

Bex guides the message review.Checkpoint: Exchange Patterns
  • Piggyback response finishes a fast CON request in one round trip by carrying payload inside ACK.
  • In the diagnostic example, an empty ACK stops request retries; a later CON carries the report. A separate response can also use NON.
  • The initial retransmission wait is randomized using ACK_TIMEOUT and ACK_RANDOM_FACTOR; subsequent waits double. A matching ACK stops retries.

Videos

The first case shows an IoT decision platform in a deployed farming context. Use it to identify where constrained field devices hand observations to a higher-level application; the video is context for the boundary, not a CoAP protocol demonstration.

The second video explains MQTT. Compare its brokered publish/subscribe model with the request/response and message-type behavior developed in this chapter; it is a comparison point rather than a lesson on CoAP REST exchanges.

Knowledge Check

Test your understanding of CoAP message types and communication patterns.

Label the Diagram

Knowledge check · self-test

Knowledge check

Test your understanding.

Code Challenge

Knowledge check · self-test

Knowledge check

Test your understanding.

See Also

Review CoAP basics first. Then see how message types shape reliable exchanges.

CoAP exchanges narrated tour

Narrated audio tour. The full transcript is below.

Play the tour to open the simulator. Pause, replay a beat, or read the full transcript below.

Some beats explain situations this teaching model cannot show; those beats keep the existing frame and provide captions only.

Full transcript — CoAP exchanges (8 beats)

B1 — Receipt versus readiness
You are the engineer responsible for an industrial gateway asking a sensor for a diagnostic report. You need the report to decide whether a machine can keep running safely. A receipt arrives quickly, but the sensor is still collecting data. When can you treat the report as ready?

Model caption: Your diagnostic report is still being prepared. The firmware-status model will illustrate how receipt and a later answer are exchanged.

B2 — CON and ACK
The Constrained Application Protocol, or CoAP, gives small devices rules for exchanging messages. A confirmable message, abbreviated CON, asks for acknowledgment and permits retransmission if acknowledgment is absent. An acknowledgment, abbreviated ACK, confirms receipt of that message. It may also carry the response's useful content, called the payload.

Model caption: Constrained Application Protocol: confirmable requests ask for acknowledgment. An acknowledgment confirms receipt and may carry useful response content.

B3 — NON and RST
Non-confirmable, abbreviated NON, means no CoAP acknowledgment is expected. Reset, abbreviated RST, means the receiver lacks the exchange context needed to process a message. For your diagnostic request, we will follow confirmable delivery, so receipt of the request gets acknowledged while the sensor prepares the report.

Model caption: NON means non-confirmable: no protocol acknowledgment is expected. RST means Reset: the receiver lacks exchange context. The diagnostic example uses confirmable delivery.

B4 — Message ID and token
Two labels do different jobs. The message identifier, called the Message ID, matches an acknowledgment to a message. The token connects an application response to its request. If an answer is ready promptly, the acknowledgment can carry it too. That combined reply is called a piggybacked response.

Model caption: Message identifier matches the acknowledgment. Token matches the answer to its request. A ready answer can travel inside the acknowledgment.

B5 — Empty receipt
Now take the chapter's diagnostic example. Collecting the report takes about eight seconds. Your gateway sends a confirmable request. The sensor promptly sends an empty acknowledgment with the request's message identifier. Request retransmissions stop, while diagnostic work continues. The empty acknowledgment carries no report.

Model caption: Chapter example: diagnostics take about eight seconds. An empty acknowledgment stops request retransmissions before the report is ready. Asset: analogous firmware-status exchange.

B6 — Separate response
After about eight seconds of diagnostic work, the sensor sends the report in a new confirmable message. Its message identifier changes, but its token matches the original request. Your gateway acknowledges the report message using its new message identifier. Each confirmable message gets an acknowledgment, making four messages in total. The result is two messaging exchanges serving one application request and response.

Model caption: Chapter result: about eight seconds of diagnostic work; four messages, two messaging exchanges, one application request and response. The later answer uses a new message identifier and the original token.

B7 — Receipt is not completion
The misconception is that receiving an acknowledgment means the requested report is complete. The empty acknowledgment disproves that: it stops retries while the report is still being prepared. The later response carries the report, and its token associates the report with your request.

Model caption: An empty acknowledgment confirms receipt while work continues. The later response supplies the answer; its token links it to the request.

B8 — Match the labels
Match acknowledgments by message identifier, match answers by token, and treat an empty receipt as a receipt.

Model caption: Match acknowledgments by message identifier, match answers by token, and treat an empty receipt as a receipt.

You are implementing a CoAP server. A client sends a CON message with Message ID 0xAB01 that references a resource your server deleted five minutes ago. The server has no cached response for this exchange. The error result is ready immediately. Which reply acknowledges receipt and reports the resource outcome?

ACK with response code 4.04 Not Found — confirm receipt and report the missing resource

Correct! The server received a valid, parseable CON message — the resource simply no longer exists. The correct response is to send an ACK (stopping retransmissions) that piggybacks a 4.04 Not Found response code. This cleanly tells the client its request was received and understood, but the target resource is unavailable. RST would imply the message itself was unprocessable or unrecognised, which is not the case here.

A server receives a CON GET with Message ID 0xAB02 for an existing resource and can return its current representation immediately. Which reply fits?

ACK with 2.05 Content and the representation

Correct. The resource exists and its representation is ready, so the server piggybacks 2.05 Content on the matching ACK.

A CoAP client sends a CON message with Message ID 0x1234, but receives an ACK with Message ID 0x5678. What should the client do?

Ignore the unrelated ACK and keep the original CON timer active.

Correct. RFC 7252 Section 4.2 requires an invalid ACK to be silently ignored. Its Message ID does not match the outstanding CON, so it cannot stop that exchange; do not answer the ACK with RST.

A client sends CON with Message ID 0x1234. It receives a valid ACK with Message ID 0x1234 before timeout. What should it do with this exchange?

Match the ACK and stop retransmitting that CON

Correct. The matching Message ID acknowledges this CON exchange, so its retransmission timer can stop.

Summary

For the freezer, choose NON only while a later sample can replace a loss within the application’s tolerance. Choose CON for an alarm needing receipt evidence, with an escalation rule if retries fail. Diagnose receipt by the Message ID and the application answer by the Token and response code. An empty ACK ends request retransmission while leaving the answer pending.

Key Takeaway

Transfer the rule to a valve command. The client receives an empty ACK, then no result. May it mark the valve closed? No: the ACK establishes message receipt, not physical completion. Stop retransmitting that acknowledged CON, wait under an application deadline for the separate response, and use application status evidence or a fallback before claiming the valve moved.

Message Exchange Patterns

Inspect the figure in the parent chapter to separate message type, response timing, method, Message ID, and Token roles before diagnosing a trace.

Read the figure in the parent chapter by comparing PIGGYBACKED with SEPARATE: the latter uses an empty ACK before the later content response. MESSAGE ID supports duplicate and ACK/RST matching, while TOKEN continues to associate a request with its separate response; GET, POST, PUT, DELETE, and multicast discovery remain application operations.

Detail notes moved from the chapter

Technical detail

Two exchanges, one application request

Review the explanation and evidence behind this section.

Open as a page

Technical detail

Two exchanges, one application request

The separate-response path exposes two independent responsibilities. Acknowledging the request resolves its delivery retry state. Sending the result later resolves the pending application answer, and a confirmable result has its own delivery exchange. The response’s changed Message ID and retained Token make those boundaries visible. Treating an empty ACK as completion would discard the very answer the gateway requested.

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.