CoAP Connector
Overview
Section titled “Overview”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 endpointsCoapWriter- Write data to CoAP endpoints
Features
Section titled “Features”- ✅ Multiple transport protocols (UDP, TCP, DTLS)
- ✅ Secure communication with DTLS
- ✅ PSK and certificate-based authentication
- ✅ GET, POST, and PUT methods
- ✅ Polling-based data acquisition
Basic Configuration
Section titled “Basic Configuration”CoAP Reader (UDP)
Section titled “CoAP Reader (UDP)”{ "type": "CoapReader", "config": { "endpoint": "192.168.1.50:5683", "transport": "UDP", "pollingRate": 5000, "path": "/sensors/temperature" }}CoAP Reader (TCP)
Section titled “CoAP Reader (TCP)”{ "type": "CoapReader", "config": { "endpoint": "192.168.1.50:5683", "transport": "TCP", "pollingRate": 5000, "path": "/sensors/all" }}CoAP Writer
Section titled “CoAP Writer”{ "type": "CoapWriter", "config": { "endpoint": "192.168.1.50:5683", "transport": "UDP", "path": "/actuators/valve", "method": "PUT" }}Configuration Parameters
Section titled “Configuration Parameters”Reader Config
Section titled “Reader Config”| Parameter | Type | Required | Description |
|---|---|---|---|
endpoint | string | ✅ | CoAP server address (host:port) |
transport | string | ✅ | Transport protocol: UDP, TCP, or DTLS |
pollingRate | integer | ✅ | Polling interval in milliseconds |
path | string | ✅ | CoAP resource path (e.g., /sensors/temp) |
dtlsConfig | object | ❌ | DTLS configuration (required for DTLS transport) |
Writer Config
Section titled “Writer Config”| Parameter | Type | Required | Description |
|---|---|---|---|
endpoint | string | ✅ | CoAP server address (host:port) |
transport | string | ✅ | Transport protocol: UDP, TCP, or DTLS |
path | string | ✅ | CoAP resource path |
method | string | ✅ | HTTP method: POST or PUT |
dtlsConfig | object | ❌ | DTLS configuration (required for DTLS transport) |
Transport Protocols
Section titled “Transport Protocols”Standard CoAP over UDP (default port 5683):
{ "endpoint": "192.168.1.50:5683", "transport": "UDP"}Best for: Low-latency, resource-constrained devices
CoAP over TCP for reliable delivery:
{ "endpoint": "192.168.1.50:5683", "transport": "TCP"}Best for: Reliable connections, larger payloads
Secure CoAP with DTLS encryption (default port 5684):
{ "endpoint": "192.168.1.50:5684", "transport": "DTLS", "dtlsConfig": { "pskIdentity": "device1", "pskKey": "c2VjcmV0a2V5" }}Best for: Secure communication over untrusted networks
DTLS Security Configuration
Section titled “DTLS Security Configuration”Pre-Shared Key (PSK)
Section titled “Pre-Shared Key (PSK)”{ "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).
Certificate-Based Authentication
Section titled “Certificate-Based Authentication”{ "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" } } }}Certificate Files (Base64)
Section titled “Certificate Files (Base64)”{ "dtlsConfig": { "certFile": { "mode": "base64", "data": "<base64-encoded-certificate>" }, "keyFile": { "mode": "base64", "data": "<base64-encoded-private-key>" }, "caCertFile": { "mode": "base64", "data": "<base64-encoded-ca-certificate>" } }}Data Format
Section titled “Data Format”Reader Response
Section titled “Reader Response”The CoAP reader expects JSON responses from the endpoint:
{ "temperature": 25.5, "humidity": 60, "battery": 85}Writer Payload
Section titled “Writer Payload”The CoAP writer sends the data payload as JSON:
{ "valve_position": 75, "mode": "auto"}Common Use Cases
Section titled “Common Use Cases”1. Sensor Network Monitoring
Section titled “1. Sensor Network Monitoring”Read from multiple sensor endpoints:
{ "type": "CoapReader", "config": { "endpoint": "192.168.1.50:5683", "transport": "UDP", "pollingRate": 10000, "path": "/sensors/environment" }}2. Secure Device Communication
Section titled “2. Secure Device Communication”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=" } }}3. Actuator Control
Section titled “3. Actuator Control”Send commands to IoT actuators:
{ "type": "CoapWriter", "config": { "endpoint": "192.168.1.100:5683", "transport": "UDP", "path": "/actuators/light", "method": "PUT" }}4. Smart Building Integration
Section titled “4. Smart Building Integration”Control building systems via CoAP:
{ "type": "CoapWriter", "config": { "endpoint": "building-controller.local:5683", "transport": "TCP", "path": "/hvac/setpoint", "method": "POST" }}Troubleshooting
Section titled “Troubleshooting”Connection Failed
Section titled “Connection Failed”Solutions:
- Verify endpoint address and port
- Check network connectivity
- Ensure CoAP server is running
- Verify transport protocol matches server configuration
DTLS Handshake Failed
Section titled “DTLS Handshake Failed”Solutions:
- Verify PSK identity and key match server configuration
- Check certificate validity and expiration
- Ensure CA certificate is correct
- Verify cipher suite compatibility
Invalid Response
Section titled “Invalid Response”Solutions:
- Ensure endpoint returns valid JSON
- Check resource path is correct
- Verify content format is application/json
- Check server logs for errors
Request Timeout
Section titled “Request Timeout”Solutions:
- Increase timeout if network is slow
- Check for network congestion
- Verify device is responsive
- Consider using TCP for unreliable networks
Best Practices
Section titled “Best Practices”- Use DTLS for Production: Always encrypt sensitive data
- Appropriate Polling Rate: Balance freshness with device battery life
- Handle Timeouts: CoAP devices may be intermittently available
- Use Observe When Available: For real-time updates (future feature)
- Resource Path Convention: Follow REST-like naming (
/sensors/temperature)