Skip to content
Try for free

ThingsBoard Cloud

Choose your data region

Your data stays in the region you choose, for residency and compliance. No credit card required.

Rather run it yourself? Install on your own servers

Attributes

The MQTT Attributes API covers three operations: publishing client-side attributes to ThingsBoard, requesting current attribute values from the server, and subscribing to server-pushed attribute updates. See Attributes for the difference between client-side, server-side, and shared attributes, and Getting Connected for connection parameters and credential types.

Report device state (serial number, firmware version, hardware config) to ThingsBoard.

Format Topic
Short v2/a
Standard v1/devices/me/attributes
{"firmwareVersion": "2.1.0", "serialNumber": "SN-4A21F", "hardwareRevision": "B"}
Terminal window
mosquitto_pub -d -q 1 -h "$THINGSBOARD_HOST" -p 1883 -t "v2/a" -u "$ACCESS_TOKEN" -m '{"firmwareVersion": "2.1.0", "serialNumber": "SN-4A21F"}'

Ask ThingsBoard for the current values of client-side or shared attributes. Useful on device boot to read back configuration stored in ThingsBoard.

Format Subscribe to responses Publish request to
Short v2/a/res/+ v2/a/req/$request_id
Standard v1/devices/me/attributes/response/+ v1/devices/me/attributes/request/$request_id

$request_id is any integer you choose; ThingsBoard echoes it in the response topic so you can match replies to requests.

Request and response payloads:

Request — specify which keys you want:

{"clientKeys": "firmwareVersion,serialNumber", "sharedKeys": "targetTemperature,enabled"}

Response:

{
"client": {"firmwareVersion": "2.1.0", "serialNumber": "SN-4A21F"},
"shared": {"targetTemperature": 24, "enabled": true}
}

Receive pushed notifications whenever a shared attribute is changed from the ThingsBoard side (e.g. an operator changes a setpoint in the dashboard).

Format Subscribe to
Short v2/a
Standard v1/devices/me/attributes

ThingsBoard publishes only the changed keys, request:

Terminal window
mosquitto_sub -d -q 1 -h "$THINGSBOARD_HOST" -p 1883 -t "v2/a" -u "$ACCESS_TOKEN"

Response:

{"targetTemperature": 26}