This topic describes how to configure data forwarding rules to send sensor data collected in a building to TSDB.
Prerequisites
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.
- Log on to the IoT Platform console.
On the Overview page, find the instance that you want to manage and click the instance ID or instance name.
- In the left navigation pane, choose , 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.
- 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" - 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 todeviceNameand its value to${deviceName}. Set the second tag name tofloorand its value to${floor}. Set the third tag name tobuildingand its value to${building}.
Query time-series data
Query the data that IoT Platform forwarded to TSDB.
- Log on to the TSDB console.
- In the Instance List, find the VPC instance that stores the data, and then click Manage on the right.
- In the left navigation pane, choose to query the data that IoT Platform forwarded to the instance. For more information, see Slow Query Log.