Connect CoAP

Publish using default schema

When a device credintials is created default schema topics is created to simplify the data transmistion

user can find device default topics in cervello following this steps:

From Device Manager -> Devices -> select device

alt text

On Device details page select Topics each topic is discriped briefly

alt text

Publish Telemetry

In order to send device telemetry user can use the default telemetry topic and schema to send device readings, then encode the device topic uri.

  • Topic: device/ACCESS_KEY/telemetry, after encoding should be device%2F%60ACCESS_KEY%60%2Ftelemetry
  • Message:
{
    "data": {
        "key": value
    },
    "ts": "unixtimestamp" #(optional)
}

In order to do encoding here are some code examples: - Hint: Make sure that the / character dosn’t exists in the URI before encoding it.

JavaScript

developer.mozilla.org

encodeURIComponent('device/`ACCESS_KEY`/telemetry'); // Native javascript function
// Result
// device%2F%60ACCESS_KEY%60%2Ftelemetry

libcoap Cli

examples/coap-client -m put -e '{"data":{"key": "string"}, "ts": "unixtimestamp"}' "coap://broker.cervello.io/device%2F%60ACCESS_KEY%60%2Ftelemetry?u={AccessKey}&p={AccessToken}"

The above cli command is divided into three sections as follows:

  • The first section examples/coap-client -m put -e which is the CoAp clint with the method of type put.
  • The second section {"data":{"key": "string"}, "ts": "unixtimestamp"} which is the message.
  • The third section "coap://broker.cervello.io/{URL}?u={AccessKey}&p={AccessToken}" which is as follows:
    • URL: The encoded URL.
    • AccessKey: The device access key.
    • AccessToken: The device access token.

alt text

once the message telemetry received and validated the data stored in device data set.

alt text

Publish Attribute

In order to send device attribute user can use the default attribute topic and schema to send device readings.

  • Topic: device/ACCESS_KEY/attribute, after encoding should be device%2F%60ACCESS_KEY%60%2Fattribute
  • Message:
{
    "data": {
        "key": value
    },
    "ts": "unixtimestamp" #(optional)
}

In order to do encoding here are some code examples: - Hint: Make sure that the / character dosn’t exists in the URI before encoding it.

JavaScript

developer.mozilla.org

encodeURIComponent('device/`ACCESS_KEY`/attribute'); // Native javascript function
// Result
// device%2F%60ACCESS_KEY%60%2Fattribute

libcoap Cli

examples/coap-client -m put -e '{"data":{"key": "string"}, "ts": "unixtimestamp"}' "coap://broker.cervello.io/device%2F%60ACCESS_KEY%60%2Fattribute?u={AccessKey}&p={AccessToken}"

The above cli command is divided into three sections as follows:

  • The first section examples/coap-client -m put -e which is the CoAp clint with the method of type put.
  • The second section {"data":{"key": "string"}, "ts": "unixtimestamp"} which is the message.
  • The third section "coap://broker.cervello.io/{URL}?u={AccessKey}&p={AccessToken}" which is as follows:
    • URL: The encoded URL.
    • AccessKey: The device access key.
    • AccessToken: The device access token.

alt text

once the message attribute received and validated the data stored in device data set.

alt text

Subscribe RPC

In order to Recieve device RPC command.

Device recieve RPC command on RPC default topic and it may acknowledge with result on the RPC Response topic

Add Command to Device

From Device Manager -> select device -> select Commands -> select Add button

alt text

Fill Form fileds [name, command, command attribute]

Command: the required command to execute on device provisded by device vendor and if the command conatins any attributes we can add them using command attribute template {{&attribute name}} and we can choose the attribute Data Type [String, Integer, Boolean, Enum] and set a default value.

alt text

Example reboot-with-delay {{&delaytime}} while delaytime is integer with default vaule 100

alt text

In order to execute command on device control select Commands -> select Execute button

alt text

We can execute directly or chnage the attributes default values then execute

alt text

RPC Topic

  • Topic: /device/ACCESS_KEY/rpc

In order to do encoding here are some code examples: - Hint: Make sure that the / character dosn’t exists in the URI before encoding it.

JavaScript

developer.mozilla.org

encodeURIComponent('device/`ACCESS_KEY`/telemetry'); // Native javascript function
// Result
// device%2F%60ACCESS_KEY%60%2Ftelemetry

libcoap Cli

examples/coap-client -m get -s 10 "coap://broker.cervello.io/device%2Fen00mfgqqxp9e9%2Frpc?u=accesskey&p=accesstoken"

The above cli command is divided into two sections as follows:

  • The first section examples/coap-client -m get -s 10 which is the CoAp clint with the method of type get and the connection timeout in seconds -s 10.
  • The second section "coap://broker.cervello.io/{URL}?u={AccessKey}&p={AccessToken}" which is as follows:
    • URL: The encoded URL.
    • AccessKey: The device access key.
    • AccessToken: The device access token.

alt text

Response Topic

once the RPC command executed subscriber receives command.

alt text

Errors

code messageKey message
401 unauthenticated Unautenticated request
403 unautherized Unautherized action