wire / wire-format / coap-message
CoAP is a lightweight REST protocol for constrained IoT devices (RFC 7252). Messages are carried over UDP. Header: version (2 bits), type (2 bits: confirmable, non-confirmable, acknowledgment, reset), token length (4 bits), code (1 byte: class.method), message ID (2 bytes). Then token, options (TLV), payload (preceded by 0xFF marker).
aka: CoAP (Constrained Application Protocol) message
spec: RFC 7252
CoAP is a lightweight REST protocol for constrained IoT devices (RFC 7252). Messages are carried over UDP. Header: version (2 bits), type (2 bits: confirmable, non-confirmable, acknowledgment, reset), token length (4 bits), code (1 byte: class.method), message ID (2 bytes). Then token, options (TLV), payload (preceded by 0xFF marker).
| field | size | meaning |
|---|---|---|
| Version | 2 bits | CoAP version (always 1). |
| Type | 2 bits | 0 CON (confirmable), 1 NON (non-confirmable), 2 ACK (acknowledgment), 3 RST (reset). |
| Token length | 4 bits | Length of the token (0-8 bytes). |
| Code | 1 byte | Class (3 bits) . Method (5 bits): 0.00 empty, 0.01 GET, 0.02 POST, 0.03 PUT, 0.04 DELETE, 2.xx success, 4.xx client error, 5.xx server error. |
| Message ID | 2 bytes (uint16) | Message identifier for matching requests to responses. |
| Token | 0-8 bytes | Token for matching requests to responses (independent of message ID). |
| Options | variable | TLV options: delta-encoded option number, length, value. Options: Uri-Host, Uri-Port, Uri-Path, Uri-Query, Content-Format, Accept, ... . |
| Payload marker | 1 byte | 0xFF (if payload present). |
| Payload | variable | The message body (e.g., JSON, CBOR, or raw bytes). |
example:
40 01 00 01 b4 54 65 73 74
CoAP CON GET request: version 1, type 0 (CON), token length 0, code 0.01 (GET), message ID 1
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/coap-message
or /wire-format/coap-message.json