CoAP · Study deck
CoAP Message Exchanges
The Constrained Application Protocol (CoAP) is a protocol for small devices and limited links.
Broker Bex is your guide for this deck.

After studying this chapter
Learning objectives
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
Major section
In 60 Seconds
The Constrained Application Protocol (CoAP) is a protocol for small devices and limited links.
- A protocol is an agreed set of exchange rules.
- A payload is the useful content carried inside a message.
- The next reading can replace a lost routine update.
- The alarm needs a clear receipt or a safe fallback.
Major section
In 60 Seconds (continued)
Treating both messages alike either wastes battery or leaves the urgent event without proof.
- CON asks for an acknowledgment and retries, so use it for commands and alarms; NON is fire-and-forget, so use it for frequent readings.
- The choice trades reliability for energy: in the worked example below, a CON exchange costs about 16× a NON one.
- The example assumes a continuously listening receiver during a 50 ms ACK wait.
Major section
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/1000.
- 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.
Major section
Four Ways to Send a Message
"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!'".
Major section
CoAP Message Types
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.
- Critical data must arrive.
Major section
CoAP Message Types (continued)
In Figure: CoAP confirmable exchange showing a CON request with, 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.
- When a newer reading makes an older one disposable, Figure: CoAP non-confirmable exchange showing a client sending replaceable shows the smaller contract.
Major section
Checkpoint: CON or NON
Decide whether routine readings or urgent freezer alarms need a receipt. Pause for eight seconds.
- 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.
Major section
Interactive: CoAP Message Energy Calculator
ACKs cost power, but their meaning is narrow: they confirm CON receipt.
- Application success still depends on the response code they carry.
- RST is a message-layer rejection, not an application error shortcut.
- An unknown Message ID or an empty CON ping can therefore produce RST.
Try it: Interactive: CoAP Message Energy Calculator in the chapter
Major section
Message Exchange Patterns
Fast work can ride inside ACK; slow work needs an empty ACK first.
- 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.
- If producing the representation takes longer than the acknowledgment window, the two jobs must separate.
Deck summary
Key takeaways
The Constrained Application Protocol (CoAP) is a protocol for small devices and limited links.
- Treating both messages alike either wastes battery or leaves the urgent event without proof.
- 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/1000.
- "I have four different ways to send my readings?" asked Temperature Terry, confused.
- CON starts a reliability exchange and waits for a matching ACK, while NON spends no acknowledgment traffic and accepts possible loss.
Retrieval practice
Recall check 1 of 6

Broker Bex says: answer from memory, then check your reasoning.
Q1A home security company deploys coin-cell window sensors. OPEN/CLOSED state changes are infrequent and must be acknowledged, with an escalation path if delivery is not confirmed. Periodic heartbeats are frequent, and a missed heartbeat can be replaced by the next one. The three-year battery target still needs measurement. Which listed message policy best balances these needs?
Show answer
Answer: C CON acknowledges and retries important state changes, while NON avoids message-layer ACK traffic for replaceable heartbeats.
Retrieval practice
Recall check 2 of 6

Broker Bex says: answer from memory, then check your reasoning.
Q2An industrial IoT gateway sends a CoAP CON request to a sensor asking for a complex diagnostic report. The sensor needs 8 seconds to collect data from multiple subsystems. What is the correct response pattern to avoid timeout issues?
Show answer
Answer: B This is the 'separate response' pattern.
Retrieval practice
Recall check 3 of 6

Broker Bex says: answer from memory, then check your reasoning.
Q3A battery-powered temperature sensor sends readings every minute to a server. Occasional loss is acceptable because the next reading replaces a missed one. Which message type should it use?
Show answer
Answer: B Non-Confirmable (NON) messages are better for this use case.
Retrieval practice
Recall check 4 of 6

Broker Bex says: answer from memory, then check your reasoning.
Q4A CoAP client sends a CON message with Message ID 0x1234, but receives an ACK with Message ID 0x5678. What should the client do?
Show answer
Answer: B RFC 7252 Section 4.2 requires a recipient to silently ignore an invalid ACK. This ACK cannot close the outstanding exchange because its Message ID differs from the CON; do not answer the ACK with RST.
Retrieval practice
Recall check 5 of 6

Broker Bex says: answer from memory, then check your reasoning.
Q5When should a CoAP client send a Reset (RST) message?
Show answer
Answer: D RST rejects a CON when the receiver lacks message context needed to process it, such as an Observe notification after a reboot.
Retrieval practice
Recall check 6 of 6

Broker Bex says: answer from memory, then check your reasoning.
Q6Complete the CoAP client that sends a confirmable request and handles the response type:
Show answer
Answer: A CON (Confirmable) messages are set via mtype=CON.
Print reference
Answers 1 of 2
Answer key.
- C · CON acknowledges and retries important state changes, while NON avoids message-layer ACK traffic for replaceable heartbeats.
- B · This is the 'separate response' pattern.
- B · Non-Confirmable (NON) messages are better for this use case.
- B · RFC 7252 Section 4.2 requires a recipient to silently ignore an invalid ACK. This ACK cannot close the outstanding exchange because its Message ID differs from the CON; do not answer the ACK with RST.
Print reference
Answers 2 of 2
Answer key.
- D · RST rejects a CON when the receiver lacks message context needed to process it, such as an Observe notification after a reboot.
- A · CON (Confirmable) messages are set via mtype=CON.