- Use case
- Prerequisites
- Step 1: Adding enrichment node
- Step 2: Default previous counter node
- Step 3: Delta transformation node
- Step 4: Setup dashboard to view the data
- TL;DR
- Next steps
Use case
Let’s assume your device is reporting absolute “counter” that correspond to water consumption. However, you would like to visualize not the “absolute” but “delta” values, e.g. how many water was consumer within last day, week, month.
In this tutorial we will calculate “delta” of the counter readings based on current and previous reading.
Assuming that previous reported value of counter was 90, we will transform incoming telemetry:
1
2
3
{
"counter": 100
}
to
1
2
3
4
{
"counter": 100,
"delta": 10
}
Prerequisites
We assume you have completed the following guides and reviewed the articles listed below:
- Getting Started guide.
- Rule Engine Overview.
- Transform Incoming Telemetry guide.
Step 1: Adding enrichment node
We will modify default rule chain and will an enrichment rule node to fetch previous telemetry value from the database and put it to the message metadata.
We will use the following node configuration:
Please note that if the “counter” value is missing, the rule node will return failure. We will protect from this failure by setting the default previous counter on the next step.
Step 2: Default previous counter node
This transformation node will set the default counter to the metadata from the incoming message. This will be used to set default “delta” value to 0 on the next step.
Step 3: Delta transformation node
This transformation node will calculate delta based on previous counter value from the metadata and current value from the message.
Step 4: Setup dashboard to view the data
We have added simple card widget to show the latest values generated by the rule chain
TL;DR
Download and import attached json file with a rule chain from this tutorial. Don’t forget to mark new rule chain as “root”.
Download and import attached json file with a dashboard from this tutorial.
Next steps
-
Getting started guides - These guides provide quick overview of main ThingsBoard features. Designed to be completed in 15-30 minutes.
-
Connect your device - Learn how to connect devices based on your connectivity technology or solution.
-
Data visualization - These guides contain instructions on 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.