Skip to content

CoAP Connector

The CoAP (Constrained Application Protocol) connector enables communication with resource-constrained IoT devices. CoAP is a lightweight protocol designed for low-power devices and lossy networks, commonly used in smart home, industrial IoT, and sensor networks.

Connector Types:

  • CoapReader - Read data from CoAP endpoints
  • CoapWriter - Write data to CoAP endpoints
  • ✅ Multiple transport protocols (UDP, TCP, DTLS)
  • ✅ Secure communication with DTLS
  • ✅ PSK and certificate-based authentication
  • ✅ GET, POST, and PUT methods
  • ✅ Polling-based data acquisition
{
"type": "CoapReader",
"config": {
"endpoint": "192.168.1.50:5683",
"transport": "UDP",
"pollingRate": 5000,
"path": "/sensors/temperature"
}
}
{
"type": "CoapReader",
"config": {
"endpoint": "192.168.1.50:5683",
"transport": "TCP",
"pollingRate": 5000,
"path": "/sensors/all"
}
}
{
"type": "CoapWriter",
"config": {
"endpoint": "192.168.1.50:5683",
"transport": "UDP",
"path": "/actuators/valve",
"method": "PUT"
}
}
ParameterTypeRequiredDescription
endpointstringCoAP server address (host:port)
transportstringTransport protocol: UDP, TCP, or DTLS
pollingRateintegerPolling interval in milliseconds
pathstringCoAP resource path (e.g., /sensors/temp)
dtlsConfigobjectDTLS configuration (required for DTLS transport)
ParameterTypeRequiredDescription
endpointstringCoAP server address (host:port)
transportstringTransport protocol: UDP, TCP, or DTLS
pathstringCoAP resource path
methodstringHTTP method: POST or PUT
dtlsConfigobjectDTLS configuration (required for DTLS transport)

Standard CoAP over UDP (default port 5683):

{
"endpoint": "192.168.1.50:5683",
"transport": "UDP"
}

Best for: Low-latency, resource-constrained devices

{
"type": "CoapReader",
"config": {
"endpoint": "192.168.1.50:5684",
"transport": "DTLS",
"pollingRate": 5000,
"path": "/sensors/secure",
"dtlsConfig": {
"pskIdentity": "bXlkZXZpY2U=",
"pskKey": "c2VjcmV0a2V5MTIz"
}
}
}

Note: pskIdentity and pskKey are byte arrays (typically base64-encoded in JSON).

{
"type": "CoapReader",
"config": {
"endpoint": "192.168.1.50:5684",
"transport": "DTLS",
"pollingRate": 5000,
"path": "/sensors/secure",
"dtlsConfig": {
"certFile": {
"mode": "path",
"data": "/certs/client.crt"
},
"keyFile": {
"mode": "path",
"data": "/certs/client.key"
},
"caCertFile": {
"mode": "path",
"data": "/certs/ca.crt"
}
}
}
}
{
"dtlsConfig": {
"certFile": {
"mode": "base64",
"data": "<base64-encoded-certificate>"
},
"keyFile": {
"mode": "base64",
"data": "<base64-encoded-private-key>"
},
"caCertFile": {
"mode": "base64",
"data": "<base64-encoded-ca-certificate>"
}
}
}

The CoAP reader expects JSON responses from the endpoint:

{
"temperature": 25.5,
"humidity": 60,
"battery": 85
}

The CoAP writer sends the data payload as JSON:

{
"valve_position": 75,
"mode": "auto"
}

Read from multiple sensor endpoints:

{
"type": "CoapReader",
"config": {
"endpoint": "192.168.1.50:5683",
"transport": "UDP",
"pollingRate": 10000,
"path": "/sensors/environment"
}
}

Connect to devices with DTLS security:

{
"type": "CoapReader",
"config": {
"endpoint": "iot-gateway.local:5684",
"transport": "DTLS",
"pollingRate": 5000,
"path": "/api/v1/data",
"dtlsConfig": {
"pskIdentity": "Z2F0ZXdheTE=",
"pskKey": "c3VwZXJzZWNyZXQ="
}
}
}

Send commands to IoT actuators:

{
"type": "CoapWriter",
"config": {
"endpoint": "192.168.1.100:5683",
"transport": "UDP",
"path": "/actuators/light",
"method": "PUT"
}
}

Control building systems via CoAP:

{
"type": "CoapWriter",
"config": {
"endpoint": "building-controller.local:5683",
"transport": "TCP",
"path": "/hvac/setpoint",
"method": "POST"
}
}

Solutions:

  • Verify endpoint address and port
  • Check network connectivity
  • Ensure CoAP server is running
  • Verify transport protocol matches server configuration

Solutions:

  • Verify PSK identity and key match server configuration
  • Check certificate validity and expiration
  • Ensure CA certificate is correct
  • Verify cipher suite compatibility

Solutions:

  • Ensure endpoint returns valid JSON
  • Check resource path is correct
  • Verify content format is application/json
  • Check server logs for errors

Solutions:

  • Increase timeout if network is slow
  • Check for network congestion
  • Verify device is responsive
  • Consider using TCP for unreliable networks
  1. Use DTLS for Production: Always encrypt sensitive data
  2. Appropriate Polling Rate: Balance freshness with device battery life
  3. Handle Timeouts: CoAP devices may be intermittently available
  4. Use Observe When Available: For real-time updates (future feature)
  5. Resource Path Convention: Follow REST-like naming (/sensors/temperature)
  • MQTT - Alternative IoT protocol
  • HTTP - REST API for capable devices
  • Filter - Filter CoAP data
  • InfluxDB - Store sensor data