6 CoAP Message Exchanges
6.1 Start With the Delivery Choice
Picture one device sending two updates: a freezer-door alarm and a routine temperature sample. The alarm needs proof that someone received it; the sample may be replaced by the next reading in a few seconds. CoAP gives those two messages different envelopes instead of forcing one rule onto both.
Read CON, NON, ACK, and RST as delivery decisions. The rest of the chapter explains what each decision costs in delay, radio time, battery, and failure handling.
6.2 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
Use this path through the protocol:
- First choose CON or NON by asking whether the next reading can replace this one.
- Then price that choice with 20-byte readings, 52-byte packets, 50 ms ACK waits, and the 16x energy ratio.
- Next separate ACK/RST protocol signals from application errors.
- 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.
Read these points as one connected sequence: start with CoAP: Constrained Application Protocol — REST-style request/response protocol using UDP instead of TCP; then Confirmable Message (CON): Requires ACK from recipient — provides reliable delivery over UDP at the cost of one roundtrip; then Non-confirmable Message (NON): Fire-and-forget UDP datagram — lowest latency, no delivery guarantee; then Observe Option: CoAP extension enabling publish/subscribe: client registers to receive notifications on resource changes; then Block-wise Transfer: Fragmentation mechanism for transferring payloads larger than a single CoAP datagram; then Token: Client-generated value matching responses to requests — enables concurrent request/response pairing; and finish with DTLS: Datagram TLS — CoAP’s security layer providing encryption and authentication over UDP.
- CoAP: Constrained Application Protocol — REST-style request/response protocol using UDP instead of TCP
- Confirmable Message (CON): Requires ACK from recipient — provides reliable delivery over UDP at the cost of one roundtrip
- Non-confirmable Message (NON): Fire-and-forget UDP datagram — lowest latency, no delivery guarantee
- Observe Option: CoAP extension enabling publish/subscribe: client registers to receive notifications on resource changes
- Block-wise Transfer: Fragmentation mechanism for transferring payloads larger than a single CoAP datagram
- Token: Client-generated value matching responses to requests — enables concurrent request/response pairing
- DTLS: Datagram TLS — CoAP’s security layer providing encryption and authentication over UDP
6.3 For Beginners: CoAP Message Types
CoAP uses four message types: Confirmable (requires acknowledgment), Non-confirmable (fire-and-forget), Acknowledgment (confirmation receipt), and Reset (error signal). Think of it like different ways to send a message — sometimes you need a read receipt, sometimes you just want to shout the news without waiting for a reply.
“I have four different ways to send my readings?” asked Temperature Terry, confused.
“Think of it like four types of mail!” said the microcontroller. “Confirmable (CON) is like certified mail — you send it and wait for a signed receipt. If you don’t get one, you send it again. Perfect for important alerts like ‘the freezer door is open!’”
the LED continued: “Non-confirmable (NON) is like dropping a flyer in someone’s mailbox — you don’t wait to see if they read it. Great for routine updates like ‘living room light is still on.’ If one update gets lost, another is coming in 10 seconds anyway.”
“Then there’s the Acknowledgment (ACK),” said the battery. “That’s the signed receipt itself — you’re saying ‘yep, I got your message!’ And Reset (RST) is like returning a letter stamped ‘wrong address’ — it means ‘I don’t understand what you’re asking for.’ Four simple types cover every situation, and they keep the protocol tiny!”
6.4 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.
6.5 CoAP Message Types
The first message-type decision is consequence: if loss changes system state, start with CON; if the next sample replaces this one, start with NON. Inspect Figure 6.1 to place ACK and RST around that sender choice.
Read Figure 6.1 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.
6.5.1 Confirmable (CON)
Reliable transmission - requires acknowledgment:
Use when:
- Critical data must arrive
- Commands that trigger actions
- Resource updates (PUT, POST, DELETE)
To see what “requires acknowledgment” means on the wire, trace one request through Figure 6.2. Keep the Message ID distinct from the Token while following the normal and timeout paths.
In Figure 6.2, 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.
6.5.2 Non-Confirmable (NON)
Unreliable transmission - no acknowledgment:
Use when:
- Frequent sensor readings
- Data loss acceptable
- Minimizing network traffic
- Battery conservation critical
When a newer reading makes an older one disposable, Figure 6.3 shows the smaller contract. Look for the deliberate absence of both an ACK timer and a retransmission loop.
Follow Figure 6.3 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 is suitable for replaceable telemetry, but not for a one-off alarm or actuator command.
Choosing between Confirmable (CON) and Non-Confirmable (NON) messages dramatically impacts battery life:
CON (Confirmable):
Read these points as one connected sequence: start with Waits for ACK response (50-200 ms typical); then Retransmits if no ACK (exponential backoff); then Radio stays on longer → drains battery; and finish with Use for: Critical commands, infrequent updates.
- Waits for ACK response (50-200 ms typical)
- Retransmits if no ACK (exponential backoff)
- Radio stays on longer → drains battery
- Use for: Critical commands, infrequent updates
NON (Non-Confirmable):
Read these points as one connected sequence: start with Fire-and-forget, no waiting; then Radio on for <10 ms; then 5-10x better battery life than CON; and finish with Use for: Frequent sensor readings where occasional loss is acceptable.
- Fire-and-forget, no waiting
- Radio on for <10 ms
- 5-10x better battery life than CON
- Use for: Frequent sensor readings where occasional loss is acceptable
Example: Temperature sensor sending readings every 60 seconds - battery lasts 2 years with NON vs 3 months with CON. For battery-powered devices, default to NON and use CON only when absolutely necessary.
Checkpoint: CON or NON
- CON fits critical data, action-triggering commands, and resource updates such as PUT, POST, and DELETE.
- NON fits frequent sensor readings where loss is acceptable and battery conservation is critical.
- A 60-second temperature sensor example estimates 2 years with NON versus 3 months with CON.
6.5.3 Worked Example: CON vs NON Energy Budget for Cold Chain Monitoring
Scenario: 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. Battery: 1,000 mAh CR123A.
NON message energy per transmission:
- TX: 20-byte payload + 4-byte CoAP header + 8-byte UDP + 20-byte IPv6 = 52 bytes
- TX time: 52 x 8 / 250,000 = 1.66 ms at 8 mA = 0.013 mAs
- Radio startup: ~0.5 ms at 8 mA = 0.004 mAs
- Total per NON: 0.017 mAs
The total energy per transmission depends on time-on-air and current draw:
For NON messages (no ACK wait):
For CON messages (with ACK wait):
Where , at for 802.15.4.
The energy ratio:
This 16× multiplier directly translates to battery life reduction when switching from NON to CON for frequent sensor readings.
6.6 ACK Wait Energy Calculation Audit
At 5% packet loss on 802.15.4, NON loses about 144 readings per day but the next one arrives in 30 seconds; CON’s retransmission drops that to about 0.25% after one retry. Decision: use NON for routine 30-second temperature readings (any loss is replaced in 30 seconds), and reserve CON for rare threshold alerts (~2 per day) such as “Temperature exceeded -18C”. This hybrid approach keeps roughly NON’s ~8-year battery life while still guaranteeing critical alerts are delivered.
Checkpoint: Energy Budget
- The cold-chain packet is 52 bytes: 20 payload + 4 CoAP + 8 UDP + 20 IPv6.
- At 250 Kbps, it takes 1.66 ms to transmit; with startup, NON costs 0.017 mAs.
- CON adds the 50 ms ACK wait and 32-byte ACK receive, reaching 0.272 mAs, about 16x NON.
6.7 Interactive: CoAP Message Energy Calculator
Explore how message type, transmission frequency, and network parameters affect battery life:
6.7.1 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)
6.7.2 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 unknown Message ID or an empty CON ping can therefore produce RST. A valid GET for a missing resource instead deserves 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.
Checkpoint: ACK and RST Semantics
- ACK confirms a valid CON and can piggyback a normal response such as 4.04 Not Found.
- RST rejects invalid, unexpected, or unprocessable protocol messages; it is not for ordinary missing resources.
- Ignoring CON causes client retries up to MAX_RETRANSMIT.
6.8 Message Exchange Patterns
After ACK and RST, choose response timing. Fast work can ride inside ACK; slow work needs an empty ACK first.
6.8.1 Piggyback Response
When the representation is already available, the server can combine transport acknowledgment and application response. Figure 6.4 shows how one packet performs both jobs without confusing their identifiers.
Read Figure 6.4 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.
6.8.2 Separate Response
If producing the representation takes longer than the acknowledgment window, the two jobs must separate. Inspect the sequence diagram in Figure 6.5 to trace that split for an eight-second diagnostic operation.
Reading the sequence diagram in Figure 6.5 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.
6.9 Interactive: CoAP Retransmission Timeline
Visualize how CoAP’s exponential backoff algorithm affects retransmission timing and battery life:
Test your recall before the detailed knowledge checks below.
Checkpoint: Exchange Patterns
- Piggyback response finishes a fast CON request in one round trip by carrying payload inside ACK.
- Separate response sends an empty ACK first, then later returns payload as a new CON for slower work such as an 8-second diagnostic report.
- Retransmission starts after ACK_TIMEOUT and uses exponential backoff plus ACK_RANDOM_FACTOR jitter.
6.10 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.
6.11 Knowledge Check
Test your understanding of CoAP message types and communication patterns.
6.12 See Also
Read these points as one connected sequence: start with CoAP Fundamentals and Architecture: Review where message types fit in the client/server architecture; then CoAP Message Reliability and Exchange Contracts: Go deeper on CON/NON/ACK/RST layering, named retransmission timers, Message ID versus Token roles, and duplicate handling; then CoAP Methods and Features: Connect CON, NON, ACK, and RST behavior to GET, POST, PUT, DELETE, and resource discovery; then CoAP Observe Extension: See how notifications use confirmable and non-confirmable messages over time; and finish with CoAP Security Applications: Relate message handling to DTLS, OSCORE, and constrained-device security choices.
- CoAP Fundamentals and Architecture: Review where message types fit in the client/server architecture.
- CoAP Message Reliability and Exchange Contracts: Go deeper on CON/NON/ACK/RST layering, named retransmission timers, Message ID versus Token roles, and duplicate handling.
- CoAP Methods and Features: Connect CON, NON, ACK, and RST behavior to GET, POST, PUT, DELETE, and resource discovery.
- CoAP Observe Extension: See how notifications use confirmable and non-confirmable messages over time.
- CoAP Security Applications: Relate message handling to DTLS, OSCORE, and constrained-device security choices.
6.13 Summary
CoAP message types separate transport reliability from application semantics. Confirmable and non-confirmable messages control acknowledgement behavior, while request methods and response codes describe the resource operation.
6.14 Key Takeaway
Choose the CoAP message type from the consequence of loss. Use confirmable messages for commands and state changes that must be acknowledged, and non-confirmable messages for replaceable telemetry where the next reading can supersede a lost one.
6.15 Message Exchange Patterns
Inspect Figure 6.6 to separate message type, response timing, method, Message ID, and Token roles before diagnosing a trace.
Read Figure 6.6 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.
