Connect MQTT

Publish Telemetry

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

  • Topic: /device/ACCESS_KEY/telemetry
  • Message:
{
    "data": {
        "key": value
    },
    "ts": "unixtimestamp" #(optional)
}

Mosquitto Cli

mosquitto_pub -d -h "broker.cervello.io" -t "/device/$ACCESS_KEY/telemetry" -i "$ACCESS_KEY" -u "$ACCESS_KEY" -P "$ACCESS_TOKEN" -f "mqtt_telemetry.json"

mqtt_telemetry.json

{
    "data": {
        "key": "test"
    }
}

MQTTBox

create publisher

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
  • Message:
{
    "data": {
        "Temperature": value
    },
    "ts": "unixtimestamp" #(optional)
}

Mosquitto Cli

mosquitto_pub -d -h "broker.cervello.io" -t "/device/$ACCESS_KEY/attribute" -i "$ACCESS_KEY" -u "$ACCESS_KEY" -P "$ACCESS_TOKEN" -f "mqtt_attribute.json"

mqtt_attribute.json

{
    "data": {
        "serialno": "test"
    }
}

MQTTBox

create publisher

alt text

once the message telemetry 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

Mosquitto Cli

mosquitto_sub -d -h "broker.cervello.io" -t "/device/{ACCESS_KEY}/rpc" -i "{ACCESS_KEY}" -u "{ACCESS_KEY}" -P "{ACCESS_TOKEN}"

alt text

MQTTBox

create subscriber and subscribe to RPC topic

alt text

once the RPC command executed subscriber receives command.

alt text

Response Topic

  • Topic: /device/ACCESS_KEY/response

Mosquitto Cli

mosquitto_pub -d -h "broker.cervello.io" -t "/device/$ACCESS_KEY/response" -i "$ACCESS_KEY" -u "$ACCESS_KEY" -P "$ACCESS_TOKEN" -m "OK"

MQTTBox

alt text

Errors

code messageKey message
401 unauthenticated Unautenticated request
403 unautherized Unautherized action