Monitoring Building Environments with TSDB

更新时间:
复制 MD 格式

This topic describes how to configure data forwarding rules to send sensor data collected in a building to TSDB.

Prerequisites

Create a sensor product and a device in the IoT Platform console, and connect the device to IoT Platform. For more information, see Quick start.
Note This example does not use a thing model. The device reports data through a custom topic.

Background information

In this scenario, two sensors are deployed on each of two floors (F1 and F2) in Building No. 1. These sensors record environmental information, such as temperature, humidity, PM2.5, and formaldehyde (HCHO) levels.

The sensors collect and report environmental data to IoT Platform every five seconds. IoT Platform then uses a data forwarding rule to send the data to TSDB. You can use the spatial aggregation and downsampling features of TSDB to easily perform data analytics.

Data reporting specifications

  • Reporting frequency: once every 5 seconds.
  • Custom data reporting topic: /${productKey}/${deviceName}/user/data.
  • Payload format:
    {"temperature":25,"humidity":24,"pm25":11,"hcho":0.02}

Configure a rule

In the Rules Engine, configure a data forwarding rule to forward device data to TSDB.

  1. Log on to the IoT Platform console.
  2. On the Overview page, find the instance that you want to manage and click the instance ID or instance name.

  3. In the left navigation pane, choose Message Forwarding > Data Forwarding, and then click Create Rule.
    Important

    If the Data Forwarding page of the latest version appears, click Back to Previous Version in the upper-right corner of the page. When the Data Forwarding page of the previous version appears, click Create Rule.

  4. Write an SQL statement to process the data. This example uses the following SQL:
    For more information, see Set data forwarding rules.
    SELECT deviceName() as deviceName, timestamp() as time, attribute('floor') as floor, attribute('building') as building, temperature, humidity, pm25, hcho FROM "/${productKey}/+/user/data"
  5. In the Forward Data section, click Add Operation to configure the data destination.

    Configure the parameters to forward data to a TSDB instance within a VPC instance.

    From the Select Operation drop-down list, select Store data in Time Series Database (TSDB). For Region, select China (Shanghai). For TSDB Instance, select your target instance. For metric, select Numeric as the data type. Set timestamp to ${time}. Add three tags. Set the first tag name to deviceName and its value to ${deviceName}. Set the second tag name to floor and its value to ${floor}. Set the third tag name to building and its value to ${building}.

Query time-series data

Query the data that IoT Platform forwarded to TSDB.

  1. Log on to the TSDB console.
  2. In the Instance List, find the VPC instance that stores the data, and then click Manage on the right.
  3. In the left navigation pane, choose Time Series Data Management > Slow Query Log to query the data that IoT Platform forwarded to the instance. For more information, see Slow Query Log.