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.
| Situation | Which 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 PLC | Modbus/TCP, OPC-UA, MELSEC |
| Via an MQTT broker | MQTT Client |
Registration form entries
| Field | What to enter | Example |
|---|---|---|
| IP address | CoAP device / gateway host | device.local, 10.20.30.40 |
| Port | CoAP standard 5683 (plaintext) / 5684 (DTLS) | 5683 |
| Collection interval | Polling 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.
| Format | Behavior |
|---|---|
/sensors/temperature | GET on the device's coap://host:5683/sensors/temperature — returns the response text |
/actuators/led | PUT on write (text/plain) — the value is the payload |
sensors/multi/T1 | Automatically 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
| Case | How |
|---|---|
| Eclipse Californium demo server | coap.me / 5683 + /test, /.well-known/core (resource discovery) |
| LoRa-WAN gateway → CoAP proxy | The gateway's CoAP API port + the per-device resource path |
| Industrial IoT sensor | Resource 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
| Symptom | Cause | Fix |
|---|---|---|
| No value arrives (read returns an empty string) | The device does not support the resource | Check the resource list with coap-client -m get coap://host:5683/.well-known/core (libcoap-bin package) |
| Reads are very slow | Network packet loss + CoAP retransmits | Increase the polling cycle, check for congestion |
| Device requires DTLS | The driver supports plaintext CoAP only | Place 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 |