RPC
Subscribe to Server-Side RPC Commands
Section titled “Subscribe to Server-Side RPC Commands”Subscribe to the RPC topic to receive commands targeted at downstream devices.
Topic: v1/gateway/rpc (subscribe + publish)
Replace GATEWAY_DEVICE_ACCESS_TOKEN in the commands below with the gateway device’s access token.
mosquitto_sub -h "mqtt.eu.thingsboard.cloud" -t "v1/gateway/rpc" -u "GATEWAY_DEVICE_ACCESS_TOKEN"Incoming command format:
{ "device": "Device A", "data": {"id": 1, "method": "toggle_gpio", "params": {"pin": 1}}}| Field | Description |
|---|---|
device |
The target device name |
data.id |
Request identifier — must be echoed in the reply |
data.method |
RPC method name |
data.params |
Method parameters (arbitrary JSON) |
Send RPC Reply
Section titled “Send RPC Reply”Send the reply to the same topic:
{"device": "Device A", "id": 1, "data": {"success": true}}mosquitto_pub -h "mqtt.eu.thingsboard.cloud" -t "v1/gateway/rpc" -u "GATEWAY_DEVICE_ACCESS_TOKEN" -m '{"device":"Device A","id":1,"data":{"success":true}}'Persistent RPC States
Section titled “Persistent RPC States”For a persistent RPC to a device behind the gateway, the gateway’s handling of the command sets the RPC state:
| Gateway | RPC state |
|---|---|
Acknowledges the command, with a QoS 1 subscription to v1/gateway/rpc |
DELIVERED |
Has a QoS 0 subscription to v1/gateway/rpc |
DELIVERED as soon as ThingsBoard sends the command |
Replies with the same id before the RPC timeout |
SUCCESSFUL, two-way RPC only |
| Doesn’t reply before the RPC timeout | EXPIRED, two-way RPC only |
A one-way RPC ends at DELIVERED, and a reply to it isn’t processed. To receive the reply, send a two-way RPC with a timeout longer than the time the device takes to respond through the gateway.
Was this helpful?