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.

messageformat
Broker Bex, the module guide, in a scene from this chapter.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.

Why it matters

For example, a cold-room node might report /temp every minute with non-confirmable readings because the next sample replaces a lost one, while a maintenance tablet sends a confirmable PUT to /defrost because a missed command changes equipment behavior.

CoAP confirmable and non-confirmable exchanges beside the compact four-byte header.
CoAP confirmable and non-confirmable exchanges beside the compact four-byte header.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
CoAP message flow between client and server compares a confirmable GET with acknowledgment, a non-confirmable PUT requiring no acknowledgment, and a slower separate response with an empty acknowledgment before the result.
CoAP message flow between client and server compares a confirmable GET with acknowledgment, a non-confirmable PUT requiring no acknowledgment, and a slower separate response with an empty acknowledgment before the result.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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.
iotclass.org

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?

AVersion and Type Bits
BToken Length Bits
CMessage ID for Duplicate Control
DCode Class.Detail Byte
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.

iotclass.org

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?

AA battery-powered controller exposes a few local resources and needs lightweight GET and PUT operations over a constrained network.
BA cloud analytics service needs thousands of backend workers to consume durable queue messages with complex routing.
CA public web API needs browser compatibility, search indexing, and ordinary HTTPS clients.
DA fleet of sensors continuously publishes telemetry to many subscribers through a central broker.
Show answer

Answer: A CoAP is designed for constrained resource-oriented request and response exchanges.

iotclass.org

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?

AThe version and extension list without command semantics or identity.
BThe URI, method, payload, code, delivery, and authorization contract.
COnly payload schema, assuming URI and method do not affect use.
DOnly UDP choice, assuming CoAP itself carries no application semantics.
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.

iotclass.org

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?

AThe message ID encrypts the payload, while the token compresses the URI path.
BThe token replaces the need for response codes, and the message ID replaces the need for methods.
CThe message ID supports ACK and duplicate handling; the token correlates a response with its request.
DBoth fields are optional labels with the same purpose, so one should always be removed.
Show answer

Answer: C Message ID matches ACKs and supports duplicate detection, while the token matches responses to requests.

iotclass.org

Print reference

Check the header and resource decisions

Answer key.

  1. B · The four-bit length tells the parser how many token bytes follow the fixed header; it does not carry the token value itself.
  2. A · CoAP is designed for constrained resource-oriented request and response exchanges.
  3. 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.
iotclass.org
1. A: Version and Type begin the header; Token Length counts token bytes; Code names method or response; Message ID handles ACK and duplicate matching. 2. A: a constrained controller with a few local resources is a plausible CoAP fit, subject to link and power tests. 3. B: include URI, method, payload, response code, delivery choice, and authorization.

Print reference

Check request and response matching

Answer key.

  1. C · Message ID matches ACKs and supports duplicate detection, while the token matches responses to requests.
iotclass.org
4. C: Message ID supports acknowledgement matching and duplicate suppression; the token pairs a response with its request. Neither proves that the valve physically moved.