立即试用 商务报价
社区版
Aggregate latest telemetry values periodically

本页目录

Aggregate latest telemetry values periodically

ThingsBoard PE功能

仅限专业版支持Analytics Rule Nodes功能。
基于ThingsBoard云服务专业版平台实例。

This tutorial will show how to calculate average temperature in the warehouse based on readings from multiple temperature sensors inside the warehouse.

Use case

Let’s assume you have a warehouse with multiple temperature sensors. For example, one per each zone. Let’s also assume temperature readings are reported by the sensor only when it detects temperature change. Thus, some sensors may have been inactive for a week although some sensors may report temperature change just recently.

In this tutorial we will configure ThingsBoard Rule Engine to automatically calculate average temperature in the warehouse based on latest readings from multiple temperature sensors every minute. 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.

We will use 1 warehouse, 2 sensors and 1 minute execution period just for demo purposes.

Prerequisites

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

Model definition

We will create one asset that has name “Warehouse A” and type “warehouse”. We will add this asset to an asset group called “Warehouses”.

image

We will create two devices that has names “Sensor A1” and “Sensor A2” and type “thermometer”. We will add this devices to device group called “Thermometers”.

image

We must also create relations between the warehouse asset and thermometers. This relation will be used in the rule chain to associate thermometer readings with the warehouse itself. It is also convenient to use relations in the dashboards to provide drill-down capabilities. You may notice two outbound relations from the warehouse asset to the thermometers on the screenshot below:

image

Note: Please review the following documentation page to learn how to create assets and relations.

Message Flow

In this section, we explain the purpose of each node in this tutorial. There will be two rule chains involved:

  • “Thermometer Emulators” - optional rule chain to simulate data from two temperature sensors;
  • “Warehouse Temperature” - rule chain that actually calculates average temperature in the warehouse;

Thermometer Emulators rule chain

image

  • Nodes A and B: Generator nodes

    • Two similar nodes that periodically generate a very simple message with random temperature reading.

    image

  • Node C: Rule Chain node

    • Forwards all messages to default rule chain.

Warehouse Temperature rule chain

image

  • Node D: Aggregate latest. Periodically (period of execution is defined as “Execution period value”) executes the following:

    • Fetches all devices related to the “Warehouse A” asset using “Contains” relation.
    • Fetches latest temperature reading for each of the devices and calculates average temperature reading.
    • Generates “POST_TELEMETRY_REQUEST” message that contains value of the average temperature.

    image

    image

  • Node E: Save telemetry node

    • Simple node that stores incoming message to the database and dispatches updates to the subscribers.

Configuring the Rule Chains

Download and import attached emulators rule chain file as a new “Thermometer Emulators” rule chain and attached warehouse temperature rule chain file as a new “Warehouse Temperature” rule chain. Please note that some nodes have debug enabled. This affects performance. Create Node C as shown on the image above in the thermometer emulators rule chain to forward telemetry to the root rule chain.

Validating the flow

Download and import attached dashboard file as a new “Warehouse Temperature” dashboard.

image

Note that you can drill down to the chart for particular warehouse by clicking on the corresponding row.

image

Next steps

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

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

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

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

  • 数据处理 - 学习如何使用ThingsBoard规则引擎。

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

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

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