CoAP Message Decoder
Decode raw CoAP message bytes and inspect version, message type, token length, request or response code, message ID, token, delta-encoded options, Uri-Path, Content-Format, Observe, Block1, Block2 and payload.
FF
separates options from the payload.
—
—
—
—
What Is a CoAP Message?
CoAP, the Constrained Application Protocol, is a compact application protocol designed for constrained devices and networks. Its message format uses a small four-byte base header followed by an optional token, options and payload.
CoAP is commonly associated with IoT devices, low-power networks, embedded systems and REST-like machine-to-machine communication.
CoAP Four-Byte Header
Byte 0:
Version | Type | Token Length
Byte 1:
Code
Bytes 2–3:
Message IDCoAP Message Types
| Type | Value | Meaning |
|---|---|---|
| CON | 0 | Confirmable |
| NON | 1 | Non-confirmable |
| ACK | 2 | Acknowledgement |
| RST | 3 | Reset |
CoAP Request Codes
| Code | Method |
|---|---|
| 0.01 | GET |
| 0.02 | POST |
| 0.03 | PUT |
| 0.04 | DELETE |
CoAP Response Codes
The high three bits of the Code byte form the class while the low five bits form the detail value. A response code such as 2.05 therefore represents class 2 with detail 5.
Code Byte = 0x45
Binary:
010 00101
Class:
2
Detail:
5
Result:
2.05 ContentCoAP Token
The token correlates requests and responses independently of the Message ID. Its length is encoded in the low four bits of the first header byte.
The common base CoAP format allows token lengths from zero through eight bytes.
CoAP Options
CoAP options use a compact delta encoding. Each option header stores a delta from the previous option number rather than repeating the full option number. Option length uses a similar compact representation.
Option Header:
High nibble:
Option Delta
Low nibble:
Option Length
Option Number =
Previous Number + DeltaCommon CoAP Options
| Number | Option |
|---|---|
| 1 | If-Match |
| 3 | Uri-Host |
| 4 | ETag |
| 6 | Observe |
| 7 | Uri-Port |
| 8 | Location-Path |
| 11 | Uri-Path |
| 12 | Content-Format |
| 14 | Max-Age |
| 15 | Uri-Query |
| 17 | Accept |
| 20 | Location-Query |
| 23 | Block2 |
| 27 | Block1 |
| 28 | Size2 |
| 35 | Proxy-Uri |
| 39 | Proxy-Scheme |
| 60 | Size1 |
CoAP Payload Marker
When a payload follows the option list, the single byte 0xFF separates options from payload data.
Options
...
FF
Payload bytesA payload marker without any following payload byte is malformed.
CoAP Block1 and Block2
Blockwise transfer options divide larger representations into smaller blocks. The option value encodes block number, the More flag and block-size exponent.
Block Value:
NUM = value >> 4
M = (value >> 3) & 1
SZX = value & 7
Block Size =
2^(SZX + 4)