ThingsBoard allows you to send Remote Procedure Calls (RPC) from server-side applications to devices and vice versa. Basically, this feature allows you to send commands to devices and receive results of commands execution. Similarly, you can execute a request from the device, apply some calculations or other server-side logic on the back-end and send the response back to the device. This guide covers ThingsBoard RPC capabilities. After reading this guide, you will get familiar with the following topics:
- RPC types;
- Basic RPC use-cases;
- RPC client-side and server-side APIs;
- RPC widgets.
RPC call types
Thinsboard RPC feature can be divided into two types based on a originator: device-originated and server-originated RPC. In order to use more familiar names, we will name device-originated RPC calls as a client-side RPC and server-originated RPC as server-side RPC.
Server-side RPC can be divided into one-way and two-way:
One-way RPC request is sent to the device without delivery confirmation and obviously does not provide any response from the device. RPC may fail only if there is no active connection with the target device within a configurable timeout period.
Two-way RPC request is sent to the device and expects to receive a response from the device within a certain timeout. The Server-side request is blocked until the target device replies to the request.
Device RPC API
ThingsBoard provides a convenient API to send and receive RPC commands from applications running on the device. This API is specific for each supported network protocol. You can review API and examples on the corresponding reference page:
Server-side RPC API
ThingsBoard provides System RPC Service that allows you to send RPC calls from server-side applications to the device. In order to send an RPC request you need to execute an HTTP POST request to the following URL:
- callType is either oneway or twoway;
- deviceId is your target Device ID.
The request body should be a valid JSON object with two elements:
- method - method name, JSON string;
- params - method parameters, JSON object.
Please note that in order to execute this request, you will need to substitute $JWT_TOKEN with a valid JWT token. This token should belong to either
- user with TENANT_ADMIN role;
- user with CUSTOMER_USER role that owns the device identified by $DEVICE_ID.
You can use the following guide to get the token.
RPC Rule Nodes
It is possible to integrate RPC actions into processing workflow. There are 2 Rule Nodes for working with RPC requests.
See widgets library for more details.