Resource model
For GET /sensors, verify both the method in Code and the resource path in Uri-Path. Neither field supplies the other.
Progress saves as you read. Mark sections complete as you go; your progress appears in the sidebar.
Related reference: CoAP message types.
A sensor receives a request for /sensors. Before accepting a parser’s output, locate the Token and the first option yourself. A wrong Token length moves the option boundary and changes every field that follows.
CoAP means Constrained Application Protocol. This page uses its base message format over User Datagram Protocol (UDP), which carries separate messages called datagrams. A byte has eight bits; hexadecimal writes a byte with two digits. A packet trace records messages observed on a link.
Predict before reading the worked decode. The fixed header is four bytes; the low four bits of the first byte give TKL. In the unseparated request below, identify the Token bytes, the first option boundary, and the path. Write your prediction, then compare it with the explanation.
42 01 7A 10 A1 B2 B7 73 65 6E 73 6F 72 73
The first byte, 42, splits into 01 | 00 | 0010: version 1, Confirmable type, and Token Length (TKL) 2. Confirmable (CON) asks the receiver for an acknowledgment. The next byte, 01, is Code 0.01, the GET method, meaning read. Code is written as class.detail: requests use class 0; response classes 2, 4, and 5 indicate success, client error, and server error. The final two header bytes hold Message ID 0x7A10, used for acknowledgment matching and duplicate detection.
Consume the next two bytes, A1 B2, as the Token: the client-selected value used to match a response to its request. Only then read B7 as an option header. Each half of this header is four bits. An option is a numbered metadata field. Here its two halves mean delta 11 and length 7: the first option number is 0 + 11 = 11, called Uri-Path, and its seven value bytes spell sensors. The path /sensors names the resource being read. All 14 bytes are accounted for; this request has no payload, the message’s application content.
Your task is to reconstruct the path, check each boundary, and distinguish message acknowledgment from response correlation. The same rules should work when another path segment or a delayed response appears.
This is part 3 of 3. Review CoAP Messages: Codes, Tokens, and Options for the preceding evidence.

Knowledge check · self-test
Knowledge check
Test your understanding.
Follow One Request to a Physical Result
A sleeping sensor wakes and receives the worked GET /sensors. Its parser first needs a valid field layout. Whether the request can wake the device, whether the sender has permission, and whether a later valve command succeeds require separate evidence.
A resource is a named item a device exposes, such as a sensor reading. Its URI path identifies it; a method says what to do with it. A GET reads a resource’s representation, the returned data describing that resource. Hypertext Transfer Protocol (HTTP) uses the same resource-and-method vocabulary. This page checks how CoAP encodes that vocabulary.
Read the leak state, repeat the request, delay the reply, send a wrong command, and restart the gateway. The valve should reach one named safe state. The receiver should distinguish no reply, refusal, and completed action.
That procedure belongs to a later system test. A gateway bridges networks; an actuator produces a physical action, such as moving a valve. A correctly decoded request or an acknowledgment alone does not prove that action occurred.
In the worked request, 01 says GET and the Uri-Path option says sensors. Together they mean read /sensors. The four-byte header frames the message; the Token connects the eventual response to this request.
A client sends requests; a server handles them. The sensor is the server here. It may return a representation of /sensors with a response Code. The method belongs in the Code byte, while the resource path belongs in options.
Message Type controls delivery handling. CON requests an acknowledgment (ACK); Non-confirmable (NON) has no message-layer acknowledgment. Reset (RST) indicates that the recipient could not process the message in its context. A NON request can still receive an application response. Type alone does not tell you whether a requested physical action succeeded.
Read the message in order: fixed header, the number of Token bytes declared by TKL, then options and any payload. Use Message ID for acknowledgment and duplicate handling, and Token for response correlation with the peer.
In the figure in the parent chapter, compare CON and NON handling, then locate Type and Message ID in the fixed header. These are the fields used to interpret acknowledgment behavior for the worked request.
The CON branch in the figure in the parent chapter shows an ACK carrying a response. A delayed response can instead arrive after an empty ACK, as the later flow figure illustrates. The NON branch has no message acknowledgment; that does not prevent a response to a NON request. For the running example, keep Message ID 0x7A10 separate from Token A1 B2 even when an ACK also carries the result.
For GET /sensors, verify both the method in Code and the resource path in Uri-Path. Neither field supplies the other.
The worked message uses four header bytes, two Token bytes, and eight option bytes. Its total is 14 CoAP bytes, excluding UDP and other network headers.
UDP carries the datagram. CoAP Type and Message ID support message handling; they do not authenticate the sender or validate the returned measurement.
First establish that this resource exchange fits the device and network. Then check the actual message boundaries rather than choosing from a protocol name alone.
Predict the new path and byte count before extending the running request: append 04 74 65 6D 70. Compare your prediction: the header 04 means delta 0 and length 4, so the option number stays 11 and the value spells temp. The repeated Uri-Path adds a second segment. The request now has 19 CoAP bytes.
Write the extended exchange beside the decoded bytes: GET, /sensors/temp, CON, Message ID 0x7A10, and Token A1 B2. Add the expected response Code and representation format so a reviewer can compare intent with the trace.
A matching response Token identifies the request within the exchange with that peer. It does not prove that the data is fresh, that the sender is authorized, or that a physical reading is correct. Keep those acceptance conditions in the record.
/sensors, then /sensors/tempGET in Code 0.01Compare the record with the trace in order. Check method and path, then header and Token boundaries, then each option length. Check ACK or RST Message ID against the message it answers; check a response Token against the outstanding request to that peer. Record representation format and freshness, and obtain separate evidence for server identity, operation permission, and any physical effect.
The worked CON uses Message ID 0x7A10 and Token A1 B2. An empty ACK can acknowledge that message by repeating its Message ID without carrying the application response. A later, separate response carries the request Token and uses a new message exchange.
To diagnose a delayed result, ask two questions: was this CON acknowledged, and which outstanding request does the response answer? The Message ID answers the first question; the Token, together with the peer, answers the second. An ACK is evidence of message handling, not proof of a completed valve action.
Use Figure 1 to compare an immediate response with a delayed, separate response.
In Figure 1, distinguish the empty acknowledgment from the later response. Match the former by Message ID and the latter by Token within the peer exchange. Then inspect the actual option and payload boundaries in a trace; a flow diagram alone cannot validate those bytes.
Match an ACK or RST to the message it answers and detect duplicates. For the running CON, the acknowledgment Message ID is 0x7A10.
Match a response to the request at that peer. A separate response to the running request carries A1 B2, even though it has its own Message ID.
Uri-Path carries sensors in the running request. Options can also describe representation format and caching. The method remains in Code.
UDP can lose, reorder, or duplicate datagrams. CoAP handles selected cases, but the application still defines acceptable consequences.
Choose CON or NON from the consequences of loss and the retry policy. For the worked GET, record whether a missing ACK or a missing response caused the timeout. If the response arrives, check the Token before accepting its data. Security, freshness, and physical effects remain separate review questions; changing the message type cannot establish them.
Reconstruct the worked request from its fields: CON GET, Message ID 0x7A10, Token A1 B2, and path /sensors. The bytes establish this encoding; they do not establish permission, freshness, or a physical outcome.
For a delayed reply, separate the acknowledgment from the application response. That distinction prevents a matching Message ID from being mistaken for a completed request.
Key Takeaway
Validate boundaries first, correlate the response with the Token and peer, then check the application result against the exchange record.

Chapter
CoAP Messages & Exchanges
Use this next to study confirmable, non-confirmable, acknowledgment, and reset exchanges in more detail.

Chapter
CoAP Message Format
Use this when you need to inspect header fields, tokens, options, payload markers, and parser evidence.

Chapter
CoAP Methods & Multicast
Use this to connect GET, POST, PUT, DELETE, multicast, Observe, and confirmable choices to practical methods.

Chapter
CoAP Resource API Design
Use this for URI shape, response-code discipline, payload design, caching, and gateway boundaries.
Decode this unseen complete datagram: 41 01 7A 11 C3 B3 61 69 72 02 72 68. ASCII 61 69 72 spells air; 72 68 spells rh. Which exchange record matches?
CON GET /air/rh, MID 0x7A11, Token C3; 12 bytes with no payload.
41 gives TKL 1. B3 declares option 11, length 3; 02 adds delta 0, length 2. The path is /air/rh. Total: 4 + 1 + 1 + 3 + 1 + 2 = 12 bytes.
A client sends CON GET /air/rh to peer S, MID 0x7A11, Token C3. S returns empty ACK MID 0x7A11, then CON 2.05 MID 0x9100, Token D4. No other requests are outstanding. What follows, and what remains unproved?
The request was acknowledged, but the response does not correlate. Investigate the Token mismatch; freshness and physical correctness remain unproved.
The ACK matches MID 0x7A11. D4 does not match request Token C3 at peer S. Even a matching Token would not establish authorization, freshness, or physical state.
For the running GET /sensors, account for every byte:
A1 B2 immediately after the header; base-format Tokens can be 0–8 bytes long.B7 declares option delta 11 and value length 7. The value spells sensors.An ACK matches the CON by Message ID. A response matches its request by Token within the peer exchange. A syntactically consistent message still needs authorization, representation validation, and freshness checks.
Decode a second unseen message before consulting feedback:
41 01 7A 11 C3 B3 61 69 72 02 72 68
Mark the header and Token, accumulate option numbers, reconstruct the path, and count the bytes. ASCII 61 69 72 spells air; 72 68 spells rh. Explain whether a two-byte Token interpretation agrees with TKL. Use the exchange-record check above to submit your prediction and reveal the worked feedback.
Check a changed boundary. Suppose the complete datagram instead ends with B7 followed by only six value bytes. Decide whether that option is complete and whether this evidence says anything about response correlation. Use the exchange-record check’s changed-case feedback to compare your reasoning.
An option delta is the difference from the previous option number, starting at zero. Its length tells you how many bytes to consume for the value. Advance over the whole value before reading another option header. If a payload is present, its 0xFF marker is recognized at an option boundary; a byte inside an option value is still part of that value.
Compare the encoding costs for the worked /sensors/temp extension:
Hypothetical format with separate one-byte number and length:
sensors: 1 + 1 + 7 = 9 bytes
temp: 1 + 1 + 4 = 6 bytes
total: 15 bytes
CoAP headers for these short options pack delta and length:
sensors: 1 + 7 = 8 bytes
temp: 1 + 4 = 5 bytes
total: 13 bytes
The two-byte saving is against that hypothetical format. It comes from packing delta and length into one byte in these examples; it is not a universal saving against HTTP or every possible absolute-number encoding.
For /sensors/temp/reading/current, the four short segments need four one-byte option headers, rather than eight header bytes in the hypothetical format. For /api/v2/devices/sensor42/temperature/readings/latest, the seven short segments need seven rather than fourteen. Both examples start with delta 11 and use delta 0 for the remaining Uri-Path options. Larger deltas or lengths need the extended encoding covered in the wire-format page.
Why sorting matters:
Options appear in nondecreasing option-number order:
Uri-Path (11), Uri-Path (11), Content-Format (12) gives deltas 11, 0, 1.Content-Format (12), Uri-Path (11) would require delta -1, which cannot be encoded.Content-Format identifies the payload representation format. Keep repeated Uri-Path segments in their path order while sorting by option number. The general rule is to accumulate option numbers and consume declared lengths, rather than guessing field boundaries from readable text.

Maths · guided foundations
Bytes, Airtime, and the Duty-Cycle Tax
Check the quantities and assumptions.
This chapter connects binary protocol details to practical implementation:
Foundation Knowledge:
Review why CoAP uses a compact message, then revisit binary representation to decode its fields.
Message Structure:
Related Protocols:
Compare the CoAP fields with other protocol encodings. Check the HTTP version before assuming its headers are text.
Implementation:
Use the implementation lab to build messages, then inspect them in Wireshark to check the encoded fields.
Specifications:
Read the message format rules first. Then look up each option number in the registry.
Tools:
Use the Wireshark reference to inspect captured fields, then try a CoAP client to produce traffic.
Binary Encoding:
Concise Binary Object Representation (CBOR) encodes application data in a payload. Review it separately from the option headers that locate and describe that payload.

Chapter
CoAP Wire Format and Option Encoding
Practice fixed-header bit decoding, option delta parsing, payload-marker boundaries, and trace review
Debugging:
Check common response errors first, then trace token matching when a response cannot be paired with its request.
Use these chapters to investigate the questions left after a boundary and correlation check:
| Chapter | Focus | Why Read It |
|---|---|---|
| CoAP Message Types | CON, NON, ACK, RST reliability mechanics | Understand exactly how retransmission timers, exponential backoff, and duplicate detection operate at the message level |
| CoAP Observe Extension | Server-push subscription model | Study how an Observe registration lets a server send later resource-change notifications |
| CoAP Block-Wise Transfers | Fragmentation of large payloads | Learn the Block1/Block2 options that split firmware images and large datasets across multiple CoAP messages |
| CoAP Implementation Labs | Hands-on Python/ESP32 coding | Apply the binary format knowledge by sending and receiving real CoAP messages with aiocoap and MicroPython |
| CoAP Security with DTLS | Encryption and authentication | Secure the tokens and payloads you now understand at the binary level using DTLS record layer wrapping |
| CoAP Fundamentals and Architecture | Resource and exchange overview | Revisit the resource model and the evidence needed to review an exchange |
This is the last part of this chapter. Return to CoAP Messages: Codes, Tokens, and Options or continue from the coap module index.

Knowledge check · self-test
__IOT_RELATED_TITLE__
__IOT_RELATED_DESCRIPTION__