ThingsBoard allows you to send remote procedure calls RPC from server-side applications to devices and vice versa.
This Tutorial is to show you how to send a remote request call to a Related Device using Rule Engine.
Let’s assume the following use case:
Note: |
Turning the Rotating System to the left or to the right is based on which way is better and faster so that the angle between the direction of the wind and the wind turbine has to be no more than 5 degrees. |
We assume you have completed the following guides and reviewed the articles listed below:
The Wind Turbine has two devices installed: Wind Direction Sensor and Rotating System.
In this section, we explain the purpose of each node in this tutorial:
The following screenshot shows how the Tutorial of RPC Call Request Rule Chain should look like:
Also, you can create the new Rule Chain from scratch. The following section shows you how to create it.
In this tutorial, you will create 8 nodes as it will be explained in the following sections:
Add the Message Type Switch node and connect it to the Input node.
This node will route the incoming messages according to the message type, namely POST_TELEMETRY_REQUEST.
Enter the Name field as Message Type Switch.
Add the Save TimeSeries node and connect it to the Message Type Switch node with a relation type Post telemetry.
This node will store TimeSeries data from incoming Message payload to the database and associate them to the Device, that is identified by the Message Originator, namely Wind Direction Sensor and Rotating System.
Enter the Name field as Save Time Series.
Field | Input Data |
Name | Fetch Wind Sensor Telemetry |
Direction | From |
Max relationship level | 1 |
Relationship type | Uses |
Entity type | Device |
Latest telemetry | true |
Source telemetry | windDirection |
Target telemetry | windDirection |
Field | Input Data |
Name | Create New Telemetry |
Originator source | Related |
Direction | To |
Max relationship level | 1 |
Relationship type | Contains |
Entity type | Asset |
var newMsg = {};
var value = Math.abs(msg.turbineDirection - metadata.windDirection);
if ((value < 180 && msg.turbineDirection < metadata.windDirection)||
(value > 180 && msg.turbineDirection > metadata.windDirection)) {
newMsg.method = 'spinLeft';
}
if ((value <= 180 && msg.turbineDirection > metadata.windDirection)||
(value >= 180 && msg.turbineDirection < metadata.windDirection)) {
newMsg.method = 'spinRight';
}
if(newMsg.method == 'spinLeft' || 'spinRight'){
msgType = 'RPC message';
}
newMsg.params = Math.round(value * 100) / 100;
return {msg: newMsg, metadata: metadata, msgType: msgType};
Add the the Filter Script node and connect it to the Transform Script node with a relation type Success.
This node will check if msgType of incoming message is RPC message.
: return msgType == 'RPC message';
This Rule chain is now ready and you need to save it.
To run the scripts, you need to do the following steps:
However, these access tokens are unique and you will need to copy the access tokens of your devices.
The following screenshot shows how the Wind Turbine Dashboard should look like:
Download the attached json file for the dashboard indicated above and import it.
The next Step is to configure the aliases used by the imported dashboard.
Click the Edit alias button and enter the input data shown in the following table:
Alias | Field | Input Data |
Wind Turbine | Filter type | Single entity |
Type | Asset | |
Asset | Wind Turbine | |
Wind Direction Sensor | Filter type | Single entity |
Type | Device | |
Device | Wind Direction Sensor | |
Rotating System | Filter type | Single entity |
Type | Device | |
Device | Rotating System |
The configuration of the dashboard is now completed and you can verify that it works as expected.
Also, you can see:
Please refer to the second link under the See Also section to see how to do this.
For more details about how RPC works in Thignsboard, please refer to the RPC capabilities guide.
Getting started guides - These guides provide quick overview of main ThingsBoard features. Designed to be completed in 15-30 minutes.
Installation guides - Learn how to setup ThingsBoard on various available operating systems.
Connect your device - Learn how to connect devices based on your connectivity technology or solution.
Data visualization - These guides contain instructions how to configure complex ThingsBoard dashboards.
IoT Data analytics - Learn how to use rule engine to perform basic analytics tasks.
Hardware samples - Learn how to connect various hardware platforms to ThingsBoard.
Advanced features - Learn about advanced ThingsBoard features.
Contribution and Development - Learn about contribution and development in ThingsBoard.