CoAP · Study deck

CoAP Messages: Parsing and Validation

A packet trace is useful only when each byte can be named.

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:

  • Explain: 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.
  • Explain: 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.
  • Explain: 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.
  • Explain: Failure boundary UDP can lose, reorder, or duplicate datagrams.
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.
  • UDP transport CoAP avoids connection setup, but the application must choose where it needs acknowledgments, retries, security, and duplicate handling.
  • Protocol fit CoAP 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 format and exchange fields showing compact header, token, options, and payload.
CoAP message format and exchange fields showing compact header, token, options, and payload.
iotclass.org

Major section

Under the Hood: Message Layer, Tokens, and Failure Boundaries (continued)

Message ID Used 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 boundary UDP 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.

  • Token Chosen by the client to correlate a response with the original request, especially when several requests are outstanding.
  • Options Carry method, URI path, content format, caching, observe registration, block-wise transfer, and other structured metadata.
  • 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 Format Use this when you need to inspect header fields, tokens, options, payload markers, and parser evidence.
  • CoAP Methods & Multicast Use 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.

Q1Place each fixed-header field where it lives so you can decode a CoAP packet and distinguish message delivery from request-response matching.

AVersion and Type Bits
BToken Length Bits
CCode Class.Detail Byte
DMessage ID for Duplicate Control
Show answer

Answer: A Place each fixed-header field where it lives so you can decode a CoAP packet and distinguish message delivery from request-response matching.

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 CoAP version and supported protocol extensions.
BURI, method, payload, code, delivery, and authorization.
COnly the payload schema, because URI and method choices do not affect interoperability.
DOnly whether the message uses UDP, because application semantics are handled below CoAP.
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 message-layer acknowledgment and duplicate handling.
DBoth fields are optional labels with the same purpose, so one should always be removed.
Show answer

Answer: C These fields serve different boundaries: transport-like message exchange and application request correlation.

iotclass.org

Print reference

Answers

Answer key.

  1. A · Place each fixed-header field where it lives so you can decode a CoAP packet and distinguish message delivery from request-response matching.
  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.
  4. C · These fields serve different boundaries: transport-like message exchange and application request correlation.
iotclass.org