Overview

Updated at:

Digital twins are decoupled from physical devices. You can use data mapping to map raw data from physical devices to the business models of digital twins. The data is mapped to the properties of the Thing Specification Language (TSL) model on the digital twin nodes. This topic describes the concepts of data mapping configuration.

Usage notes

Data mapping consists of the following three parts:

Configuration item

Description

Data source type

Data source types include the following:

  • Topic data: Data from custom device topics, topics for reporting TSL model properties, and data parsed in DataService Studio.

    The data source is used as input data for the script file or output file.

    • Data from custom topics is in the raw data format that is reported by the device.

    • For the data format of topics that are used to report TSL model properties, see Device property reporting.

    • Data that is parsed in DataService Studio is in JSON format.

  • API data: The data mapping configuration is triggered by calling the ImportDTData API operation to map data to digital twins.

  • Data table: Data from a custom storage table that flows back to the IoT Digital Twin Engine. The table has fixed fields, and the data is directly mapped to the corresponding digital twin nodes.

    • value: The value is of the double type.

    • iot_id: The iotId of a twin node in a twin entity.

    • property_id: The identifier of a property in a twin node.

    For information about how to configure a data table, see Create and manage custom storage tables.

Script file

Use JavaScript to write a script that parses and processes data from the configured data source, and then outputs data in JSON format. The file size cannot exceed 128 KB.

Output file

Use the specified JSON data format to map data from the data source, or data processed by the script, to the TSL model properties of a specified digital twin node. The file size cannot exceed 256 KB.

For more information about how to edit script files and output files, see Script and output syntax.

Scenarios

Data mapping is used in the following scenarios:

  • If the data source is a TSL model property topic, you can complete the data mapping using an output file. A script file is not required. The following figure shows this process.物模型Topic无脚本

  • If the data source is a custom topic or the data is from an API and is in JSON format, you can complete the data mapping using an output file. A script file is not required. The following figure shows this process.自定义Topic无脚本

  • If the data source is a custom topic, you must first use a script file to parse and process the data. Then, you can use an output file to complete the data mapping. The following figure shows this process.自定义Topic有脚本

  • If the data source is data parsed in DataService Studio, a data parsing task can perform complex processing and calculations on raw device data. For more information, see Data parsing. To process and calculate the raw device data, you can first transfer the device data to a data analytics task for more complex processing. Then, set the destination node for data parsing to IoT Digital Twin and use an output file to complete the data mapping. The following figure shows this process.

    image

    Important

    In the output data format for data parsing, payload and ts are system fields. The payload field represents the data output from the parsing process. The ts field represents the processing timestamp in UTC and is measured in milliseconds.

  • If the data source is data from a custom storage table in DataService Studio, a script file and an output file are not required. The value of the value field is directly mapped to the TSL model property of the corresponding digital twin node based on the values of the iotId and identifier fields.

    Important

    The data type for data mapped from a custom storage table in DataService Studio to the IoT Digital Twin Engine is always String. The IoT Digital Twin Engine converts the string to the property type of the corresponding digital twin node. If the conversion fails, the operation is skipped.

How to configure data mapping

Add a data source