CoAP Driver — Technical Reference
The CoAP driver in PlantPulse Edge is a Java implementation wrapping the Eclipse Californium 3.13.0 library. It accesses resource URIs on low-power IoT devices (RFC 7252) via GET / PUT.
Source: plantpulse.driver.protocol.coap.*
| Class | Responsibility |
|---|---|
CoAPDriver | ProtocolDriver implementation — connect/read(GET)/write(PUT)/close, per-resource CoapClient cache |
Libraries:
lib/californium-core-3.13.0.jarlib/element-connector-3.13.0.jar
Operation Flow
[connect] CoapClient(baseUri) 생성 → setConnected(true)
↓
[read] resource path → resourceUri = baseUri + "/" + path
→ resourceClients.computeIfAbsent(uri, CoapClient::new)
→ CoapClient.get() (synchronous)
→ resp.isSuccess() ? resp.getResponseText() : ""
↓
[write] resourceClients.computeIfAbsent(uri, CoapClient::new)
→ CoapClient.put(value, MediaTypeRegistry.TEXT_PLAIN /* 0 */)
→ resp.isSuccess()
↓
[close] 모든 CoapClient.shutdown() + resourceClients.clear()
Since CoAP runs over UDP, it is connectionless — simply creating the client object is treated as "connected." Actual device availability is confirmed at the first read.
Options (BasicDriverSource.options)
This driver has no options. The only values used for the connection are host and port.
dtls · psk-identity · psk-key has no effectThe driver always builds the connection URI as coap://. Even if you set dtls=true in the options or
specify the DTLS standard port 5684, traffic goes out as plaintext CoAP — and since no error
is raised, it is easy to mistakenly assume the traffic is encrypted.
For devices that require DTLS, place a DTLS-terminating gateway in front of the device and have this driver read the plaintext side of the gateway.
Request timeouts cannot be specified either. The Californium defaults apply as-is.
For devices with slow responses, increase the collection interval (timecycle) instead of adjusting the timeout.
Address (resource path) Format
| Format | Conversion Result |
|---|---|
/sensors/temperature | coap://host:5683/sensors/temperature |
sensors/temperature | coap://host:5683/sensors/temperature (leading / added automatically) |
/.well-known/core | Device resource discovery — list of registered resources (CoRE Link Format) |
A CoapClient is cached per resource so sockets are reused. All are shut down on close().
Response Handling
| Californium Response | Driver Handling |
|---|---|
resp == null | read = "", write = false |
resp.isSuccess() (2.xx) | read = resp.getResponseText(), write = true |
resp.getCode() error (4.xx / 5.xx) | warn log + read = "", write = false |
CoAP response text is returned as a String as-is regardless of mediaType — if the device responds with JSON,
the caller (PlantPulse's JsonExtract) decodes it. CBOR responses are shown as text, so a separate decoder is required (not currently supported).
Unit Tests
test/java/plantpulse/driver/protocol/coap/CoAPDriverTest.java — 13 methods:
- Class load + initial state
- Meta (isWriteSupported / isExternal / getDriverSource)
- Safe read / write while not connected (no NPE)
- close() safety
baseUri()— explicit / default portresourceUri()— leading/correctiongetDebugBaseUrl()—coap://host:port
Build-isolated tests with no network calls (./gradlew test green).