Skip to content
Stand with Ukraine flag

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.

FormatTopic
Shortv2/a
Standardv1/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.

FormatSubscribe to responsesPublish request to
Shortv2/a/res/+v2/a/req/$request_id
Standardv1/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).

FormatSubscribe to
Shortv2/a
Standardv1/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}