IoT Hub
IoT Hub Documentation
Guides > Tutorials > Basics > Transform telemetry using previous record
Getting Started Documentation
API FAQ

On this page

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

  • Getting started guides - These guides provide quick overview of main IoT Hub features. Designed to be completed in 15-30 minutes.