wire / wire-format / coap-message

CoAP (Constrained Application Protocol) 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).

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: CoAP (Constrained Application Protocol) message

wire format

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).

fieldsizemeaning
Version2 bitsCoAP version (always 1).
Type2 bits0 CON (confirmable), 1 NON (non-confirmable), 2 ACK (acknowledgment), 3 RST (reset).
Token length4 bitsLength of the token (0-8 bytes).
Code1 byteClass (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 ID2 bytes (uint16)Message identifier for matching requests to responses.
Token0-8 bytesToken for matching requests to responses (independent of message ID).
OptionsvariableTLV options: delta-encoded option number, length, value. Options: Uri-Host, Uri-Port, Uri-Path, Uri-Query, Content-Format, Accept, ... .
Payload marker1 byte0xFF (if payload present).
PayloadvariableThe 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


provenance

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/coap-message or /wire-format/coap-message.json