立即试用 商务报价
社区版
指南 > Tutorials > Basics > Transform telemetry using previous record

本页目录

Transform telemetry using previous record

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:

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.

image

We will use the following node configuration:

image

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.

image

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.

image

Step 4: Setup dashboard to view the data

We have added simple card widget to show the latest values generated by the rule chain

image

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”.

image

Download and import attached json file with a dashboard from this tutorial.

Next steps

  • 入门指南 - 快速学习ThingsBoard相关功能。

  • 安装指南 - 学习如何在各种操作系统上安装ThingsBoard。

  • 连接设备 - 学习如何根据你的连接方式或解决方案连接设备。

  • 可 视 化 - 学习如何配置复杂的ThingsBoard仪表板说明。

  • 数据分析 - 学习如何使用规则引擎执行基本的分析任务。

  • 硬件样品 - 学习如何将各种硬件平台连接到ThingsBoard。

  • 高级功能 - 学习高级ThingsBoard功能。

  • 开发指南 - 学习ThingsBoard中的贡献和开发。