Stand with Ukraine flag
Try it now Pricing
Edge
Documentation > Use Cases > Data filtering and traffic reduce
Getting Started
Devices Library Installation Architecture API FAQ
On this page

Data filtering and traffic reduce

Use case

This use case demonstrates how to configure an “in-vehicle IoT monitoring system” connected to ThingsBoard Edge platform.

The goal is to collect data from various sensors, process it locally on the Edge, and selectively push relevant data (e.g., mileage readings) to the cloud. This setup ensures efficient tracking of the remaining mileage until the next oil change.

To achieve this, we will configure the “Edge Root Rule Chain” to process sensor readings locally on the ThingsBoard Edge platform. This setup will handle inputs from all 10 sensors and use a rule node to filter and forward only the distance readings (mileage) to the cloud.

The “in-vehicle monitoring system” includes 10 sensors:

  • Distance
  • Gas consumption
  • Vehicle speed
  • Engine temperature
  • Ambient temperature
  • Tire temperature
  • Pressure in each tire (4x)

ThingsBoard Edge has the following responsibilities:

  • Collecting readings from all 10 sensors
  • Sending only “distance” readings to the cloud

Please note that this is just a simple theoretical use case to demonstrate the capabilities of the platform. You can use this tutorial as a basis for much more complex scenarios.

Prerequisites

We assume you have completed the following guides and reviewed the articles listed below:

Please make sure that you have ThingsBoard server up and running. Additionally, ThingsBoard Edge must be up, running and connected to the cloud.

If you have these prerequisites in place let’s go to next steps.

In other case please visit this link to provision, install and connect Edge to Server guide.

Doc info icon

For simplicity we are going to refer to server UI URL as SERVER_URL despite if you installed ThingsBoard server on-previse or using cloud host version. Edge UI URL respectively as EDGE_URL below in tutorial.

Doc info icon

If you changed the Edge HTTP bind port to 18080 during Edge installation, use the following ThingsBoard Edge UI link: http://localhost:18080.

Create device

To begin, let’s create a new device named “In-vehicle monitoring system” on the Edge.

Please open ThingsBoard Edge UI using the URL EDGE_URL.

  • Log in to your ThingsBoard Edge instance and navigate to the "Devices" page.
  • Click on the ("+") icon located in the top right corner. Then, click "Add new device" button.
  • Enter the Name of the input device, for example, "In-vehicle monitoring system", then click "Add" button.
  • Now, your device named "In-vehicle monitoring system" should appear in the devices table.

Please open ThingsBoard using the URL SERVER_URL:

  • Log in to your ThingsBoard server instance and navigate to the "Devices" page.
  • Please verify that the device "In-vehicle monitoring system" is listed in the devices list.

Configure edge rule engine to push filtered data to the cloud

We will update “Edge Root Rule Chain” that will be saving on the edge 10 sensor readings. In the rule chain we add rule node that transforms incoming messages and pushes to the cloud message only with distance readings. Here is the final configuration of the edge root rule chain:

In the next steps, we will create a TBEL node to filter data. The TBEL script language node will create an empty object newMsg, add a property named “distance” with the corresponding value from the “In-vehicle monitoring system”, and then send the newMsg object as a new message.

1
2
3
var newMsg = {};
newMsg.distance = msg.distance;
return { msg: newMsg, metadata: metadata, msgType: msgType }; 

Here are the steps to update the default Edge “Root Rule Chain” with the provided rule chain:

  • Log in to your ThingsBoard instance. Open the "Rule chain templates" page. Navigate to "Edge management" and select "Rule chain templates". Finally, click on "Edge Root Rule Chain".
  • Use the filter to search for nodes containing the word "script". Drag the Script node (Transformation) to the rule chain.
  • Input the node name, e.g., "Transform Incoming Message" and add the JavaScript code (please copy and paste it from the snippet above) to send further only "distance" readings.
  • Delete the connection between the "save timeseries" and "push to cloud" nodes. Select the connection path, then click on the ("X") icon to delete it.
  • Drag a connection from the "save timeseries" to the transformation script node.
  • Choose "Success" from the dropdown list, and click the "Add" button.
  • Drag a connection from "Transform Incoming Message" to the "push to cloud" node.
  • Choose "Success" from the dropdown list, and click the "Add" button.
  • Click "Apply Changes" to save your progress.

Now let’s open ThingsBoard Edge UI to see updated Root Rule Chain:

  • Log in to your ThingsBoard Edge instance and navigate to the "Rule chains" page.
  • Open the "Edge Root Rule Chain" to verify the changes.
  • You should see the same configuration of rule chain nodes as on the cloud.

Connect device to edge and post telemetry

To connect “In-vehicle monitoring system” to the ThingsBoard Edge you need to get device credentials first. ThingsBoard supports different device credentials. We recommend to use default auto-generated credentials which is access token for this guide.

Please open ThingsBoard Edge UI using the URL: EDGE_URL.

  • Open Devices page in the ThingsBoard Edge instance.
  • Click on the "In-vehicle monitoring system" device row in the table to open device details.
  • Click on the "Copy access token" button. The token will be copied to your clipboard.

We will use simple commands to generate random telemetry for the device “In-vehicle monitoring system” and publish to the ThingsBoard Edge by the MQTT protocol.

Please download following script to your local folder:

Before running the scripts, please modify mqtt-generator.py as follows:

  • Replace YOUR_ACCESS_TOKEN with the access token of the “In-vehicle monitoring system” device copied from the previous steps.

  • Replace YOUR_TB_EDGE_HOST with your ThingsBoard Edge host address. For example, localhost.

  • Replace YOUR_TB_EDGE_MQTT_PORT with your ThingsBoard Edge MQTT port number. For example, 11883 or 1883.

Open the terminal and install the MQTT Python library using the following command:

1
sudo pip install paho-mqtt

Navigate to the directory containing your Python script and launch the application with the following command:

1
python mqtt-generator.py

Open the ThingsBoard Edge UI and verify that the device successfully receives telemetry:

  • Navigate to the "Devices" page.
  • Click on the "In-vehicle monitoring system" device row in the table to open the device details.
  • Click on the "Copy Access Token" button. The token will be copied to your clipboard.

Open ThingsBoard UI and verify that edge successfully pushes data to the cloud:

  • Log in in to your ThingsBoard instance and open "Devices" page.
  • Click on the row labeled "In-vehicle monitoring system" in the table to view its details.
  • Click on the "Latest telemetry" tab to confirm that distance readings are successfully being pushed from the edge to the cloud.

Create dashboard

In the following steps, we will create a dashboard that displays both the total miles traveled and the remaining miles until the next oil change for the vehicle.

Please open ThingsBoard to create a new dashboard:

  • Log in to your ThingsBoard instance. Navigate to the "Dashboards" page.
  • Click on the ("+") "Add" icon and select "Create new dashboard".
  • Enter a title for the new dashboard, e.g., "Edge Vehicle". Click on the "Add" button to create the dashboard.
  • Click on the "Edge Vehicle" dashboard in the table to start editing it.
  • Click on the "Entity aliases" icon located in the toolbar at the top right to open the "Entity aliases" menu.
  • Click on the "Add alias" button.
  • Enter "edge device" into the Alias name field. For the Filter type, select "Single entity". In the Type field, choose "Device". Then, in the Device field, select "In-vehicle monitoring system". Finally, click the "Save" button.
  • Click on the "Add Widget" button.
  • Click on the "Widgets Bundle" and find "Digital gauges". Click on it to open the widget list group.
  • Select the widget from the list that matches the image provided in the guide, then click on it to start adding a data source.
  • In the "Type" dropdown menu, select "Entity". In the "Entity Alias" dropdown menu, select "edge device". In the "Data Key" field, select "distance". Then click the "Add" button to apply changes.
  • Click on the "Edit Widget" icon in the upper right corner of the widget to add style.
  • Select the "Appearance" tab to customize your dashboard widget.
  • Set max value to "10000".
  • Input the unit title as "MLS". Click the "Add" button to apply changes.
  • Dashboard widget successfully created.

Congratulations! You have successfully sent telemetry from the device, saved it on the edge, pushed filtered data to the cloud, and visualized it on the dashboard.

Next Steps