Edge
ThingsBoard Documentation
Cloud Professional Edition Community Edition Edge IoT Gateway License Server Trendz Analytics
Try it now Pricing
Documentation > Use Cases > Data filtering and traffic reduce > Professional Edition
Getting Started
Installation Architecture

On this page

Data filtering and traffic reduce - ThingsBoard Professional Edition

Use case

Let’s assume you have a vehicle with mounted IoT monitoring system connected to ThingsBoard Edge. You want to collect all messages from the device on the edge and push to the cloud only data related to business logic. For example, mileage readings may help to track how many miles left to travel till the next oil change.

The In-vehicle monitoring system has 10 sensors:

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

ThingsBoard Edge has the following responsibilities:

  • Collects readings from 10 sensors
  • Pushes to the cloud only “distance” readings

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 Professional Edition 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 edge on server Provision Edge on ThingsBoard Professional Edition server.

Once Edge provisioned on a server, please install it and connect to server using this guide.

For simplicity we are going to refer to server UI URL as http://SERVER_URL despite if you installed ThingsBoard server on-previse or using cloud host version.

Edge UI URL respectively as http://EDGE_URL below in tutorial.

If during installation process you have changed edge HTTP_BIND_PORT please use that port instead for Edge UI URL:

http://localhost:HTTP_BIND_PORT

Create device

First we will create a new device “In-vehicle monitoring system” on the edge.

Please open ThingsBoard Edge UI using the URL http://EDGE_URL.

  • Login to your ThingsBoard Edge instance and open Device groups page.
  • Open "All" device group.
  • Click on the "Add Device"("+") icon in the top right corner of the table.
  • Input device name. For example, "In-vehicle monitoring system". Click "Add" to add the device.
  • Now your "In-vehicle monitoring system" device should be in the devices table.

Please open ThingsBoard ThingsBoard Professional Edition using the URL http://SERVER_URL:

  • Login to your ThingsBoard ThingsBoard Professional Edition instance. Open the group All of the Device groups page.
  • Make sure that "In-vehicle monitoring system" device is 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 are going to create JavaScript node to filter data. JavaScript for script node will create an empty object newMsg, add property “distance” with corresponding value from the “In-vehicle monitoring system” and send further object newMsg as a new message:

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

Please use this snippet in the next steps, if required.

Here are the steps to update default edge “Root Rule Chain” to the rule chain above:

  • Login to your ThingsBoard ThingsBoard Professional Edition instance and open Rule chain templates page.
  • Click "Open rule chain" icon to start editing "Edge Root Rule Chain".
  • Filter node by "script" word and drag script node (Transformation) to rule chain.
  • Input node name, e.g. "Transform incoming message" and add JavaScript code (you can copy and paste it from the snippet above) to send further only "distance" readings. Click "Add" to proceed.
  • Remove connection between nodes "Save Timeseries" and newly added script node.
  • Drag connection from "Save Timeseries" to the transformation script node.
  • Select "Success" from the list and click "Add" button.
  • Drag connection from "Transform incoming message" to the "Push to cloud" node the list and click "Add" button.
  • Select "Success" from the list and click "Add" button.
  • Click "Apply changes" to save current progress.

Now let’s open ThingsBoard Edge UI to see updated root rule chain:

  • Login to your ThingsBoard Edge instance and open Rule chains page.
  • Open "Edge root rule chain" to verify changes.
  • You should see the same rule chain nodes configuration 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: http://EDGE_URL.

  • Open Device groups page in the ThingsBoard Edge instance.
  • Open "All" device group.
  • Click on the In-vehicle monitoring system device row in the table to open device details.
  • Click "Copy access token". Token will be copied to your clipboard. Save it to a safe place.

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 accordingly:

  • Replace YOUR_ACCESS_TOKEN with In-vehicle monitoring system device access token copied from the steps above.

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

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

Open the terminal and install MQTT Python library:

1
sudo pip install paho-mqtt

Go to the folder that contains Python script and launch an application by this command:

1
python mqtt-generator.py

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

  • Open Device groups page in the ThingsBoard Edge instance.
  • Open "All" device group.
  • Click on the In-vehicle monitoring system device row in the table to open device details.
  • Click on the tab Latest telemetry. You should see the telemetry constantly generated by the Python script.

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

  • Login to your ThingsBoard ThingsBoard Professional Edition instance and open Device groups page.
  • Open All device group.
  • Click on the row In-vehicle monitoring system to open device details.
  • Click on the tab Latest telemetry to verify that distance readings are pushed successfully from the edge to the cloud.

Create dashboard

Also we will create a dashboard that displays how many miles has been traveled and how many are left to change the oil in the vehicle.

Please open ThingsBoard ThingsBoard Professional Edition to create a new dashboard:

  • Login to your ThingsBoard ThingsBoard Professional Edition instance and open "Dashboard groups" page.
  • Click on the "Add entity group" ("+") icon in the upper right corner. Input name "Edge dashboards" and click "Add".
  • Open "Edge dashboards" group by clicking on the "Open" icon.
  • Click on the "Add" ("+") icon. Input title for the new dashboard, e.g. "Edge Vehicle" and click "Add".
  • Click on the icon "Open dashboard" of the newly created dashboard.
  • To start editing dashboard click on the "Edit" icon in the lower right corner.
  • Click "Entity aliases" icon to add a new alias in order to visualize data on the dashboard.
  • Click "Add alias" button.
  • Input alias name "edge device". Select Filter type - "Single entity", Type - "Device", Device - "In-vehicle monitoring system". Then click "Add" button.
  • Click "Save" button to save new alias.
  • Click "Add new widget" in the middle of the dashboard page.
  • Click "Select widgets bundle" and find "Digital gauges".
  • In the list of available widgets select the one you see on the image. Click "+ Add" button to add a datasource for the widget.
  • Click "+ Add" button to add a new datasource.
  • Select Entity alias "edge device" and click on choose "distance" as device timeseries.
  • Click "Edit widget" icon in the upper right corner of the widget to add style.
  • Click "Setting" tab and add you can optionally add some title, icon and display configurations as show on the image.
  • Click "Advanced" tab, input Maximum value as "1000" and Unit title as "MLS". Then click "Apply changes" and close the card.
  • Optionally you can also resize widget by dragging the left bottom corner of the widget. Do not forget to click "Apply changes" icon to save current progress.
  • Your dashboard should be similar to the one you see on the image.

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

Next Steps