CoAP Device API Reference
Last updated
Last updated
CoAP basics
is a light-weight IoT protocol for constrained devices. You can find more information about CoAP . CoAP protocol is UDP based, but similar to HTTP it uses request-response model. CoAP observes allows to subscribe to resources and receive notifications on resource change.
JIoT server nodes act as a CoAP Server that supports both regular and observe requests.
Client libraries setup
You can find CoAP client libraries for different programming languages on the web. Examples in this article will be based on . In order to setup this tool, you can use instructions in our guide.
CoAP Authentication and error codes
We will use access token device credentials in this article and they will be referred to later as $ACCESS_TOKEN. The application needs to include $ACCESS_TOKEN as a path parameter into each CoAP request. Possible error codes and their reasons:
4.00 Bad Request - Invalid URL, request parameters or body.
4.01 Unauthorized - Invalid $ACCESS_TOKEN.
4.04 Not Found - Resource not found.
By default, JIoT supports key-value content in JSON. Key is always a string, while value can be either string, boolean, double or long. Using custom binary format or some serialization framework is also possible. See protocol customization for more details. For example:
In order to publish telemetry data to JIoT server node, send POST request to the following URL:
The simplest supported data formats are:
or
Please note that in this case, the server-side timestamp will be assigned to uploaded data!
In case your device is able to get the client-side timestamp, you can use following format:
Example
telemetry-data-as-object.json
telemetry-data-as-array.json
telemetry-data-with-ts.json
JIoT attributes API allows devices to
Upload client-side device attributes to the server.
Request client-side and shared device attributes from the server.
Subscribe to shared device attributes from the server.
Publish attribute update to the server
In order to publish client-side device attributes to JIoT server node, send POST request to the following URL:
Example
new-attributes-values.json
Request attribute values from the server
In order to request client-side or shared device attributes to JIoT server node, send GET request to the following URL:
Example
Result
Please note, the intersection of client-side and shared device attribute keys is a bad practice! However, it is still possible to have same keys for client, shared or even server-side attributes.
Subscribe to attribute updates from the server
In order to subscribe to shared device attribute changes, send GET request with Observe option to the following URL:
Once shared attribute will be changed by one of the server-side components (REST API or Rule Chain) the client will receive the following update:
Example
Result
Server-side RPC
In order to subscribe to RPC commands from the server, send GET request with observe flag to the following URL:
Once subscribed, a client may receive rpc requests. An example of RPC request body is shown below:
where
id - request id, integer request identifier
method - RPC method name, string
params - RPC method params, custom json object
and can reply to them using POST request to the following URL:
where $id is an integer request identifier.
Example Subcribe
Example Reply
Reply Body
Client-side RPC
In order to send RPC commands to the server, send POST request to the following URL:
Both request and response body should be valid JSON documents. The content of the documents is specific to the rule node that will handle your request.
Example Request
Request Body
Response Body
CoAP transport can be fully customized for specific use-case by changing the corresponding module.
In the example above, we assume that “1451649600512” is a with milliseconds precision. For example, the value ‘1451649600512’ corresponds to ‘Fri, 01 Jan 2016 12:00:00.512 GMT’