akenza.io
Search…
CoAP
This page describes the CoAP connectivity in more detail
If a device communicates over CoAP with akenza, a CoAP device connector has to be set up and assigned to a Data Flow.
After creation, a secret is generated which has to be provided in the request. Both the secret and the device ID are set as query params in the CoAP request.
NOTE: The akenza CoAP connector currently only supports JSON content format. Make sure to provide the appropriate header for it.

Sample nodeJS Script

The below sample nodeJS script allows sending a CoAP uplink. It requires the node module coap to be installed.
1
const coap = require('coap');
2
3
// define connection options
4
const options = {
5
hostname: "coap.akenza.io",
6
port: 5683,
7
method: "POST",
8
pathname: "/v3/capture",
9
query: "secret={secret}&deviceId={deviceId}",
10
options: {
11
"Content-Format": "application/json",
12
},
13
};
14
// create the request object
15
const req = coap.request(options);
16
// set the payload
17
const payload = {
18
temperature: Math.random() * 100,
19
};
20
req.write(JSON.stringify(payload));
21
// handle success response
22
req.on('response', function (res) {
23
res.pipe(process.stdout);
24
});
25
// handle error response
26
req.on('error', function (err) {
27
console.log("error while sending coap request", err);
28
});
29
// send the request
30
req.end();
Copied!
Last modified 3mo ago