Attributes
Publish Client-Side Attributes
Section titled “Publish Client-Side Attributes”Upload client-side attributes for one or more devices.
Topic: v1/gateway/attributes
{ "Device A": {"fw_version": "1.0", "battery": 87}, "Device B": {"fw_version": "2.1", "battery": 92}}Replace GATEWAY_DEVICE_ACCESS_TOKEN in the commands below with the gateway device’s access token.
mosquitto_pub -h "mqtt.thingsboard.cloud" -t "v1/gateway/attributes" -u "GATEWAY_DEVICE_ACCESS_TOKEN" -m '{"Device A":{"fw_version":"1.0","battery":87}}'Request Attribute Values
Section titled “Request Attribute Values”Subscribe to the response topic first, then publish the request.
Subscribe: v1/gateway/attributes/response
Publish: v1/gateway/attributes/request
| Field | Required | Description |
|---|---|---|
id | Yes | Integer request identifier — echoed in the response |
device | Yes | Device name |
keys | Yes | Array of attribute keys to return |
client | Yes | Boolean flag: set to true to request client-side attributes, or false to request shared attributes |
{ "id": 1, "device": "Device A", "keys": ["fw_version", "battery"], "client": true}{ "id": 1, "device": "Device A", "keys": ["state", "level"], "client": false}Example:
The gateway keeps a single MQTT connection open per device, so use mosquitto_rr: it subscribes, publishes the request, and waits for the response over that one connection, matching the request/response pattern this API expects.
Replace GATEWAY_DEVICE_ACCESS_TOKEN in the commands below with the gateway device’s access token.
mosquitto_rr -d -q 1 -h "mqtt.thingsboard.cloud" -p 1883 -t "v1/gateway/attributes/request" -e "v1/gateway/attributes/response" -u "GATEWAY_DEVICE_ACCESS_TOKEN" -m '{"id":1,"device":"Device A","keys":["fw_version","battery"],"client":true}'mosquitto_rr -d -q 1 -h "mqtt.thingsboard.cloud" -p 1883 -t "v1/gateway/attributes/request" -e "v1/gateway/attributes/response" -u "GATEWAY_DEVICE_ACCESS_TOKEN" -m '{"id":1,"device":"Device A","keys":["state","level"],"client":false}'Subscribe to Shared Attribute Updates
Section titled “Subscribe to Shared Attribute Updates”Subscribe to receive push notifications when shared attributes change for any downstream device.
Topic: v1/gateway/attributes (subscribe)
mosquitto_sub -h "mqtt.thingsboard.cloud" -t "v1/gateway/attributes" -u "$ACCESS_TOKEN"ThingsBoard delivers updates in this format:
{ "device": "Device A", "data": {"targetFwVersion": "2.0", "enabled": true}}Was this helpful?