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}

The body can be any JSON object.

Query Parameters

NameTypeDescription

timestamp

string

The timestamp of the event (ISO-8601 formatted - the current time will be used if not provided)

topic

string

The data topic ("default" will be used if not provided)

uplinkSecret

string

The uplink secret used to authenticate the request

deviceId

string

The device ID

Headers

NameTypeDescription

content_format

number

application/json

{
    "id": "UUID",
    "timestamp": "ISO-8601 date string",
    "message": "uplink received"
}

Sample nodeJS Script

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 updated