Skip to main content

CoAP (IoT)

Constrained Application Protocol (RFC 7252) — the RESTful communication standard for low-power IoT devices. Being UDP-based, it uses small packets and little power. The gateway accesses a device's resource URIs with GET / PUT.

SituationWhich card to use
Low-power IoT device (behind a LoRa-WAN gateway, battery-powered sensor)CoAP (this page)
General IoT gateway (HTTP API)HTTP
Industrial PLCModbus/TCP, OPC-UA, MELSEC
Via an MQTT brokerMQTT Client

Registration form entries​

FieldWhat to enterExample
IP addressCoAP device / gateway hostdevice.local, 10.20.30.40
PortCoAP standard 5683 (plaintext) / 5684 (DTLS)5683
Collection intervalPolling interval (ms)5000 (use a longer value for battery-powered devices)

PLC address notation for tags — resource path​

A tag's PLC address = CoAP resource URI path.

FormatBehavior
/sensors/temperatureGET on the device's coap://host:5683/sensors/temperature — returns the response text
/actuators/ledPUT on write (text/plain) — the value is the payload
sensors/multi/T1Automatically corrected if the leading / is missing

Read calls are synchronous GETs — a request goes directly to the device on every polling cycle. For battery-powered devices, set a long polling cycle (5000–60000 ms) to reduce how often the device is woken from sleep.


Common use cases​

CaseHow
Eclipse Californium demo servercoap.me / 5683 + /test, /.well-known/core (resource discovery)
LoRa-WAN gateway → CoAP proxyThe gateway's CoAP API port + the per-device resource path
Industrial IoT sensorResource path from the manufacturer's manual (/sensor/X) — usually a text response

write (PUT)​

Writing a value from the tag page or the REST API sends a PUT request (mediaType text/plain) to the device.

plc_address = /actuators/led
value = ON
→ PUT coap://host:5683/actuators/led payload="ON" Content-Format: text/plain

If the response is a success (2.04 Changed, etc.), the write succeeded.


Common problems and fixes​

SymptomCauseFix
No value arrives (read returns an empty string)The device does not support the resourceCheck the resource list with coap-client -m get coap://host:5683/.well-known/core (libcoap-bin package)
Reads are very slowNetwork packet loss + CoAP retransmitsIncrease the polling cycle, check for congestion
Device requires DTLSThe driver supports plaintext CoAP onlyPlace a DTLS-terminating gateway in front of the device and read from the gateway's plaintext side. Neither the dtls option nor specifying port 5684 will solve this

More detailed technical documentation​