libcoap usage
Local client
Build the client container:
docker build --target client --platform linux/amd64 -t coap-client .
docker run --rm -it coap-client /bin/bash
To test the client once in the client container:
# works on mac (supposedly not on linux), need to change networking depending on what step of dev you are on
# IMPORTANT: this should fail because dtls is required
coap-client -m post -T d7b9 -e @data.json -f data.json -t 'application/json' coap://host.docker.internal:5683/telemetry
# be sure to change the url to coap.vibrantbt.net if testing deployment or ipv6 address in brackets with quotes, see infrastructure/README.md
coap-client -m post -T d7b9 -e @data.json -f data.json -t 'application/json' \
-c /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-cert.pem \
-j /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-key.pem \
-R /client/certs/ca-cert.crt \
coaps://host.docker.internal:5684/telemetry
Time endpoint examples
# Without DTLS (should fail if DTLS required)
coap-client -m get coap://host.docker.internal:5683/time
# With DTLS (recommended)
coap-client -m get \
-c /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-cert.pem \
-j /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-key.pem \
-R /client/certs/ca-cert.crt \
coaps://host.docker.internal:5684/time
Device Endpoints (No DTLS)
For local development where NO_DTLS_OK=1 is set on the broker.
# Set your target environment variables
export COAP_HOST="homeassistant.local"
export DEVICE_ID="4253d73e-22e3-b1e9-0000-000000000000"
Device Settings
Get Desired Settings
coap-client -m get \
coap://${COAP_HOST}:5683/device/${DEVICE_ID}/settings
Subscribe to Settings Changes (Observe)
# Keep connection open for 100 seconds and print notifications
coap-client -m get -s 100 \
coap://${COAP_HOST}:5683/device/${DEVICE_ID}/settings
Update Reported Settings
# Example payload
echo '{"mode":"auto","fan_speed":50}' > settings.json
coap-client -m put \
-t "application/json" \
-f settings.json \
coap://${COAP_HOST}:5683/device/${DEVICE_ID}/settings
Device Logs
echo '{"level":"info","message":"System boot complete","uptime":15}' > log.json
coap-client -m post \
-t "application/json" \
-f log.json \
coap://${COAP_HOST}:5683/device/${DEVICE_ID}/logs
Device Status
echo '{"state":"online","rssi":-65,"firmware":"1.0.0"}' > status.json
coap-client -m post \
-t "application/json" \
-f status.json \
coap://${COAP_HOST}:5683/device/${DEVICE_ID}/status
Telemetry (Device Specific)
ERV (Energy Recovery Ventilator)
cat <<EOF > erv_telemetry.json
{
"metrics": {
"erv_supply_sen66_temp": 22.1,
"erv_supply_sen66_humidity": 45.5,
"erv_exhaust_diff_pressure": 12.0,
"erv_supply_sen66_pm25": 2.5,
"erv_supply_sc16_co": 0.1
}
}
EOF
coap-client -m post \
-t "application/json" \
-f erv_telemetry.json \
coap://${COAP_HOST}:5683/device/${DEVICE_ID}/telemetry
Sense (Air Quality Sensor)
cat <<EOF > sense_telemetry.json
{
"metrics": {
"sense_sen66_temp": 23.0,
"sense_sen66_humidity": 50.0,
"sense_yc16_co2": 520,
"sense_sen66_voc": 100
}
}
EOF
coap-client -m post \
-t "application/json" \
-f sense_telemetry.json \
coap://${COAP_HOST}:5683/device/${DEVICE_ID}/telemetry
Gateway (GW)
cat <<EOF > gw_telemetry.json
{
"metrics": {
"gw_vibrant_device_count": 4,
"gw_nonvibrant_device_count": 2
}
}
EOF
coap-client -m post \
-t "application/json" \
-f gw_telemetry.json \
coap://${COAP_HOST}:5683/device/${DEVICE_ID}/telemetry
Media Cleaner (MC)
cat <<EOF > mc_telemetry.json
{
"metrics": {
"mc_diff_pressure": 25.0,
"mc_voc_index": 120,
"mc_airspeed": 1.5
}
}
EOF
coap-client -m post \
-t "application/json" \
-f mc_telemetry.json \
coap://${COAP_HOST}:5683/device/${DEVICE_ID}/telemetry
remote test client if local ipv6 issues
If your local network is causing you issues, you can launch this container directly in the cluster using the following commands:
docker build --target client --platform linux/amd64 -t michaelvibrant/coap-client:latest .
docker push michaelvibrant/coap-client:latest
kubectl run coap-client-test \
--image=michaelvibrant/coap-client:latest \
--rm -it --restart=Never \
--command -- /bin/bash
Once in the container:
coap-client -m post -T d7b9 -e @data.json -f data.json -t 'application/json' \
-c /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-cert.pem \
-j /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-key.pem \
-R /client/certs/ca-cert.crt \
coaps://coap.vibrantbt.net:5684/telemetry
# be sure to change ipv6 address as needed
coap-client -m post -T d7b9 -e @data.json -f data.json -t 'application/json' \
-c /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-cert.pem \
-j /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-key.pem \
-R /client/certs/ca-cert.crt \
'coaps://[2600:3c06::f03c:95ff:fe23:25af]:5684/telemetry'
# Time endpoint examples
coap-client -m get \
-c /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-cert.pem \
-j /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-key.pem \
-R /client/certs/ca-cert.crt \
coaps://coap.vibrantbt.net:5684/time
# IPv6 example (update address)
coap-client -m get \
-c /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-cert.pem \
-j /client/certs/4ed0b099-9bf5-4e85-ad64-f41ed32de4c7-key.pem \
-R /client/certs/ca-cert.crt \
'coaps://[2600:3c06::f03c:95ff:fe23:25af]:5684/time'