DeviceHive CoAP-Websockets proxy written in Node.js
Prerequisite: DeviceHive WebSocket API endpoint.
- Run CoAP proxy:
docker build -t coap-proxy .
docker run -e DEBUG=coap-proxy -e PROXY.TARGET=ws://localhost/api/websocket coap-proxy
- In order to check connectivity run Node.js or Python example. Detailed instructions could be found here.
- At the first step, issuing
Observe
request to CoAP proxy will open a new connection and create WebSocket session with the targeted DeviceHive instance; - If connection was successfully established you'd receive socket
id
in the response (id of your Websocket session); - All further requests should be non-
Observe
and contain111
header with the specified socketid
(from the previous step); - All further responses will be pushed as a responses to the initial
Observe
request (which socketID were specified as a value of111
header. See how it was handled in our examples: Node.js and Python); - DeviceHive CoAP API is identical to the Websocket one. Please, follow this link to explore detailed description of supported message formats.
This proxy has 5 properties to configure, you can override them with environment variables:
PROXY.HOST
— Proxy server host (default localhost);PROXY.PORT
— Proxy server port (default 5683);PROXY.TARGET
— DeviceHive WebSocket API endpoint;PROXY.MAX_WS_CONNECTIONS
— Maximum number of Websocket connections that proxy is able to establish. After it reaches this value new CoAP clients won't be able to send new Observe requests;DEBUG
— To enable debug logging specify coap-proxy;
Or you can mount a volume to the Docker container (config
directory).
In order to establish new connection you'd initiate Observe
request. In response you'd receive:
- Response with
id
property with value of your socket (you should use it for future non-Observe
requests in111
header)
OR error
property with error message in case of failure.