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.
post
coap://coap.akenza.io
/v3/capture?secret={uplinkSecret}&deviceId={deviceId}
Send a CoAP Uplink
The below sample nodeJS script allows sending a CoAP uplink. It requires the node module coap to be installed.
const coap = require('coap');
// define connection options
const options = {
hostname: "coap.akenza.io",
port: 5683,
method: "POST",
pathname: "/v3/capture",
query: "secret={secret}&deviceId={deviceId}",
options: {
"Content-Format": "application/json",
},
};
// create the request object
const req = coap.request(options);
// set the payload
const payload = {
temperature: Math.random() * 100,
};
req.write(JSON.stringify(payload));
// handle success response
req.on('response', function (res) {
res.pipe(process.stdout);
});
// handle error response
req.on('error', function (err) {
console.log("error while sending coap request", err);
});
// send the request
req.end();
Last modified 2yr ago