Skip to content
© 2026 The ThingsBoard Authors
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

RPC

ThingsBoard supports both server-initiated and device-initiated RPC over CoAP. For a full explanation of the RPC model, see Command & Control.

See Getting Connected for credential types and connection details.

The device subscribes to commands using the CoAP Observe option. When a server-side RPC is triggered (from the Rule Engine, REST API, or a dashboard widget), ThingsBoard pushes it to the observing client.

Credential type URL
Access Token coap(s)://THINGSBOARD_HOST/api/v1/$ACCESS_TOKEN/rpc
X.509 Certificate coaps://THINGSBOARD_HOST/api/v1/rpc

Access Token:

Terminal window
coap-client -v 6 -m GET -s 60 "coap://$THINGSBOARD_HOST:5683/api/v1/$ACCESS_TOKEN/rpc"

X.509 Certificate:

Terminal window
coap-client-openssl -v 6 -c cert.pem -j key.pem -m GET -s 60 "coaps://$THINGSBOARD_HOST/api/v1/rpc"

You subscribe and observe for 60 seconds (-s 60). When a command arrives, the response body contains:

{
"id": 1,
"method": "setGpio",
"params": {"pin": 23, "value": 1}
}
Field Description
id Integer request identifier — use this in the reply
method RPC method name
params Method parameters (arbitrary JSON)

The device sends a reply to a two-way server-side RPC call with a POST request:

Credential type URL
Access Token coap(s)://THINGSBOARD_HOST/api/v1/$ACCESS_TOKEN/rpc/{id}
X.509 Certificate coaps://THINGSBOARD_HOST/api/v1/rpc/{id}

Access Token:

Terminal window
coap-client -v 6 -m POST -t "application/json" -e '{"result":"ok"}' "coap://$THINGSBOARD_HOST:5683/api/v1/$ACCESS_TOKEN/rpc/1"

X.509 Certificate:

Terminal window
coap-client-openssl -v 6 -c cert.pem -j key.pem -m POST -t "application/json" -e '{"result":"ok"}' "coaps://$THINGSBOARD_HOST/api/v1/rpc/1"

Replace 1 with the id value from the received command.

The device initiates an RPC call to the server with a POST request:

Credential type URL
Access Token coap(s)://THINGSBOARD_HOST/api/v1/$ACCESS_TOKEN/rpc
X.509 Certificate coaps://THINGSBOARD_HOST/api/v1/rpc

Access Token:

Terminal window
coap-client -v 6 -m POST -t "application/json" -e '{"method":"getTime","params":{}}' "coap://$THINGSBOARD_HOST:5683/api/v1/$ACCESS_TOKEN/rpc"

X.509 Certificate:

Terminal window
coap-client-openssl -v 6 -c cert.pem -j key.pem -m POST -t "application/json" -e '{"method":"getTime","params":{}}' "coaps://$THINGSBOARD_HOST/api/v1/rpc"

The Rule Engine processes the request and the response body contains the result returned by the RPC reply node:

{"time": "2026-01-01T12:00:00Z"}

When the device profile payload type is set to Protobuf, the request and response use fixed schemas. See MQTT RPC for the Protobuf schemas.