CoAP · Study deck
CoAP Messages: Parsing and Validation
A packet trace records messages seen on a link.
Broker Bex is your guide for this deck.

After studying this chapter
Learning objectives
You will be able to:
- Label the fields in a complete CoAP message.
- Validate option encoding and request-response matching.
- Explain: A web-like request is useful only if the device can handle it within its power and link limits.
- Explain: User Datagram Protocol (UDP) means sending separate messages without a lasting connection.
Major section
CoAP Fundamentals
A web-like request is useful only if the device can handle it within its power and link limits.
- A protocol means shared rules for an exchange.
- Hypertext Transfer Protocol (HTTP) means a request-and-response format used by web systems.
- Constrained Application Protocol (CoAP) means a compact request method for small devices.
- CoAP starts from that everyday constraint.
Major section
CoAP Fundamentals (continued)
User Datagram Protocol (UDP) means sending separate messages without a lasting connection.
- A gateway means the bridge between local devices and a wider network.
- An actuator means a part that creates a physical action.
- The valve should reach one named safe state.
- The receiver should distinguish no reply, refusal, and completed action.
Major section
Overview: CoAP Makes Resources Cheap Enough for Constrained Nodes
The difference is the operating environment.
- CoAP is built for small devices and constrained networks, so it runs over UDP and keeps the base message compact.
- The practical value is not that CoAP imitates the web.
- A temperature sensor can expose /sensors/temp.
- A valve controller can accept a PUT to /actuators/valve.
Major section
Overview: CoAP Makes Resources Cheap Enough for Constrained Nodes (continued)
MQTT fits brokered telemetry streams.
- The value is that it lets a sensor, actuator, or local gateway expose a small resource interface without carrying a full web stack on every exchange.
- A commissioning tool can discover resources before it writes a control rule.
- HTTP fits broad web and cloud integration.
Major section
Overview: CoAP Makes Resources Cheap Enough for Constrained Nodes (continued)
Both exchanges use the same resource model, but the message type, retry expectation, and review evidence differ.
- If you only need the intuition, remember this: use CoAP when a constrained node needs REST-like request and response behavior, UDP is acceptable, and the system can make reliability choices per message.
- Clients use URI paths, methods, response codes, and representations to read or change state.
- The Code byte encodes the method, while the Token and numbered Options carry correlation, URI, content format, caching, and other metadata.
- Protocol fitCoAP fits constrained request-response and local control.
Major section
Practitioner: Write the CoAP Exchange Record
A CoAP design should be reviewed as an exchange record, not just as a protocol name.
- The record names the resource, method, payload format, expected response, message type, security boundary, and the evidence that the exchange works under expected loss and latency.
- This keeps design conversations concrete.
- Response code and state change match the method.
Major section
Under the Hood: Message Layer, Tokens, and Failure Boundaries
CoAP has two important layers of meaning.
- The message ID helps detect duplicates at the message layer.
- The token correlates a response with the request that caused it, which matters when several requests are in flight.
- A confirmable message asks for an acknowledgment and may be retransmitted if no acknowledgment arrives.
Major section
Under the Hood: Message Layer, Tokens, and Failure Boundaries (continued)
Message IDUsed by endpoints to match acknowledgments and suppress duplicates at the message exchange boundary.
- A non-confirmable message avoids that exchange when loss is acceptable or the next reading will replace the old one.
- Options carry resource and representation metadata.
- Failure boundaryUDP can lose, reorder, or duplicate datagrams.
Major section
Under the Hood: Message Layer, Tokens, and Failure Boundaries (continued)
Keeping those roles separate makes later failure analysis precise instead of treating every identifier as a request ID.
- TokenChosen by the client to correlate a response with the original request, especially when several requests are outstanding.
- OptionsCarry URI path, content format, caching, observe registration, block-wise transfer, and other structured metadata; the method is in the Code byte.
- CoAP handles selected cases, but the application still defines acceptable consequences.
Major section
Under the Hood: Message Layer, Tokens, and Failure Boundaries (continued)
For a large representation, block-wise transfer limits the work repeated after loss.
- If clients need change-driven updates, add Observe only with explicit notification rate limits and cancellation.
- CoAP Message FormatUse this when you need to inspect header fields, tokens, options, payload markers, and parser evidence.
- CoAP Methods & MulticastUse this to connect GET, POST, PUT, DELETE, multicast, Observe, and confirmable choices to practical methods.
Deck summary
Key takeaways
A web-like request is useful only if the device can handle it within its power and link limits.
- User Datagram Protocol (UDP) means sending separate messages without a lasting connection.
- The difference is the operating environment.
- MQTT fits brokered telemetry streams.
- Both exchanges use the same resource model, but the message type, retry expectation, and review evidence differ.
Retrieval practice
Recall check 1 of 4

Broker Bex says: answer from memory, then check your reasoning.
Q1What tells a CoAP parser how many token bytes follow the fixed header?
Show answer
Answer: B The four-bit length tells the parser how many token bytes follow the fixed header; it does not carry the token value itself.
Retrieval practice
Recall check 2 of 4

Broker Bex says: answer from memory, then check your reasoning.
Q2Which situation is the clearest fit for CoAP?
Show answer
Answer: A CoAP is designed for constrained resource-oriented request and response exchanges.
Retrieval practice
Recall check 3 of 4

Broker Bex says: answer from memory, then check your reasoning.
Q3A team is documenting a CoAP command that changes a pump setpoint. Which item is most important to include in the exchange record?
Show answer
Answer: B A control command needs a full exchange record: URI, method, payload format, response code, confirmable delivery choice, authorization boundary, and trace evidence so reviewers can assess semantics, safety, security, and observed behavior.
Retrieval practice
Recall check 4 of 4

Broker Bex says: answer from memory, then check your reasoning.
Q4Why does CoAP include both a message ID and a token?
Show answer
Answer: C Message ID matches ACKs and supports duplicate detection, while the token matches responses to requests.
Print reference
Check the header and resource decisions
Answer key.
- B · The four-bit length tells the parser how many token bytes follow the fixed header; it does not carry the token value itself.
- A · CoAP is designed for constrained resource-oriented request and response exchanges.
- B · A control command needs a full exchange record: URI, method, payload format, response code, confirmable delivery choice, authorization boundary, and trace evidence so reviewers can assess semantics, safety, security, and observed behavior.
Print reference
Check request and response matching
Answer key.
- C · Message ID matches ACKs and supports duplicate detection, while the token matches responses to requests.