If you use a public IoT Platform instance, you can configure data forwarding rules
to forward processed data to TSDB. This article describes the data forwarding process. In this example, a Thing Specification
Language (TSL) communication topic is used as the source topic.
Background information
In this example, the following data is written to TSDB:
- timestamp: Use the
timestamp()
function to obtain the time when a device submits data.
- tag: Use the
deviceName()
function to obtain the DeviceName. The {"deviceName":deviceName()}
tag is written to the database.
- metric: Use JSONPath expressions to obtain the values of the Temperature and Humidity properties that are submitted by the device.
Limits
- Data can be forwarded only within a region. For example, you can only forward data
from an IoT Platform instance that is deployed in the Japan (Tokyo) region to a TSDB instance that is deployed in the Japan (Tokyo) region.
- You can forward data only to a TSDB instance that is deployed in a VPC.
- You can forward data only in the JSON format.
- Only TSDB is supported. Time Series Database for InfluxDB® and Ganos are not supported.
- In the forwarded messages, all fields are written to TSDB as the metric, except for the fields that are configured as the timestamp and tag value. The data types of the metric parameter support numeric and string. If you use other data types, data may fail
to be written to the database.
Create a data destination
- Log on to the IoT Platform console.
- On the Overview page, find the instance and click the instance name to go to the Instance Details page.
Notice Enterprise Edition instances are available only in the China (shanghai) and Japan
(Tokyo) region. If your IoT Platform is not activated in the China (shanghai) or Japan
(Tokyo) region, skip this step.

- In the left-side navigation pane, choose .
- Optional:On the Data Forwarding page, click Go to New Version in the upper-right corner to go to the new version.
Note If you have performed this step, the Data Forwarding page of the new version appears after you choose Rules > Data Forwarding.
- Click the Data Destination tab. On this tab, click Create Data Destination.
- In the Create Data Destination dialog box, enter a data destination name. In this example, enter DataPurpose. Set the parameters and then click OK.
Parameter |
Description |
Select Operation |
Select Save to TSDB.
|
Region |
Specify the region where your IoT Platform instance resides. |
TSDB Instance |
Specify the TSDB instance that you have created. |
metric Data Type |
Specify the data type of the metric parameter. Valid values: numeric and string.
For more information, click the icon.
|
Role |
Grant IoT Platform the permissions to write data to TSDB. |
Configure and start a parser
- Create a parser named DataParser. For more information, see Create a parser.
- On the Parser Details page, associate the parser with the created data source.
- In the Data Source step of the wizard, click Associate Data Source.
- In the dialog box that appears, select DataSource from the Data Source drop-down list, and then click OK.
- On the Parser Details page, associate the parser with the created data destination.
- Click Data Destination in the wizard. In the Data Destination section, click Associate Data Destination.
- In the dialog box that appears, select DataPurpose from the Data Destination drop-down list, and then click OK.
- In the Data Destination section, view and save the data destination ID. In this example, the ID is 1000.
When you write the parser script, you must use the data destination ID.
- On the Parser Details page, click Parser.
- In the code editor, enter a script. For more information about how to write a script,
see Sample script.
For more information about the function parameters, see Functions.// Use the payload() function to obtain the data that is submitted by devices and convert the data by using the JSON format.
var data = payload("json");
// Filter the submitted temperature and humidity values.
var h = data.items.Humidity.value;
var t = data.items.Temperature.value;
// Forward submitted TSL data.
writeTsdb(1000,timestamp(),"temperature", t , {"deviceName":deviceName()});
writeTsdb(1000,timestamp(),"humidity", h , {"deviceName":deviceName()});
- Click Debugging. In the dialog box that appears, select a product and a device, specify a topic,
and enter payload data to verify whether the script can run properly.
The following figure shows the parameters.

The following result indicates that the script is implemented.

- Click Publish.
- Go to the Parser tab of the Data Forwarding page. Find the DataParser parser and click Start in the Actions column to start the parser.