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
On Device details page select Topics
each topic is discriped briefly
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.
ACCESS_KEY
/telemetry, after encoding should be device%2F%60ACCESS_KEY%60%2Ftelemetry
{
"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
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:
examples/coap-client
-m put -e
which is the CoAp clint with the method of type put
.{"data":{"key": "string"}, "ts": "unixtimestamp"}
which is the message."coap://broker.cervello.io/{URL}?u={AccessKey}&p={AccessToken}"
which is as follows:
once the message telemetry received and validated the data stored in device data set.
In order to send device attribute user can use the default attribute topic and schema to send device readings.
ACCESS_KEY
/attribute, after encoding should be device%2F%60ACCESS_KEY%60%2Fattribute
{
"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
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:
examples/coap-client
-m put -e
which is the CoAp clint with the method of type put
.{"data":{"key": "string"}, "ts": "unixtimestamp"}
which is the message."coap://broker.cervello.io/{URL}?u={AccessKey}&p={AccessToken}"
which is as follows:
once the message attribute received and validated the data stored in device data set.
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
From Device Manager -> select device -> select Commands
-> select Add
button
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.
Example reboot-with-delay {{&delaytime}} while delaytime
is integer with default vaule 100
In order to execute command on device control select Commands
-> select Execute
button
We can execute directly or chnage the attributes default values then execute
ACCESS_KEY
/rpcIn 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
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:
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
."coap://broker.cervello.io/{URL}?u={AccessKey}&p={AccessToken}"
which is as follows:
once the RPC command executed subscriber receives command.
code | messageKey | message |
---|---|---|
401 | unauthenticated | Unautenticated request |
403 | unautherized | Unautherized action |