Import a TSL model

Updated at:
Copy as MD

A Thing Specification Language (TSL) model defines a device's properties, events, and services. You can add these features to a product in batches by importing a pre-configured TSL model JSON file or copying the TSL model from another product.

Prerequisites

A product has been created. For more information, see Create a product.

Usage

  • TSL model features are not supported for MQTT-based instances. Therefore, you cannot add TSL models to these instances.

  • Because this action overwrites all existing feature definitions for the product, use this feature with caution.

  • You cannot import a TSL model for gateway sub-device products that use Modbus, OPC UA, ZigBee, or BLE as the gateway connection protocol.

  • To add or edit the TSL model of a published product, you must first unpublish it.

  • If you import a TSL model from another product, both products must belong to the same category.

  • For products that belong to a standard category, you cannot modify the feature type, identifier, or data type of standard features. You also cannot delete mandatory standard features.

Add a TSL model

  1. Log on to the IoT Platform console.

  2. In the upper-left corner of the console, select the region where your instance is located.

  3. On the Instance Overview tab, under All Environments, find your instance and click the instance card.

  4. In the left-side navigation pane, choose Devices > Product.

  5. On the Product page, find the product that you want to manage and click View in the Actions column.

  6. On the product details page, click the Define Feature tab, and then click Edit Draft.

  7. Click Import. In the dialog box that appears, import the TSL model.

    You can import features in batches in one of two ways:

    • On the Copy Product tab, select the source product and TSL model version, and then click OK.

      The Thing Specification Language models for the default and custom modules of the corresponding version of the source product will be imported. On the Edit Draft page of Define Feature, you can click the Edit button for a feature in a module to modify the feature definition.

    • On the Import TSL tab, upload a single TSL model JSON file or a ZIP package that contains multiple JSON files.

      For information about how to create and package TSL model files, see What is a TSL model?.

      Note

      If the file does not meet the requirements, a validation error is reported after the upload. You must fix the issues indicated in the error message and re-upload the file. For more information about how to troubleshoot validation failures, see What do I do if a TSL validation fails during import?

    • While the TSL model imports, you cannot add, edit, delete, or publish modules or features on the draft page.

    • If the import fails, an error message appears with the reason for the failure. You can fix the issue based on the message and try importing again.

    • After a successful import, the existing TSL models of the product's default and custom modules are overwritten.

Publish the TSL model

Important

A TSL model must be published to take effect.

  1. In the lower-left corner of the Edit Draft page for Feature Definition, click Publish. The Publish TSL Model? dialog box appears.

  2. Optional: Click Add Publication Note, and enter a version number and description.

    Parameter

    Description

    Version Number

    Set the version number for the current TSL model. You can manage TSL models based on version numbers later.

    The version number supports letters, digits, and periods (.). It can be 1 to 16 characters in length.

    Version Description

    Describe the current version of the TSL model. Supports Chinese characters, letters, Japanese characters, digits, and special symbols. The description can be up to 100 characters in length. A Chinese or Japanese character is counted as one character.

  3. If an online version exists, compare it with the new version to confirm the changes.

    Click Comparison Result to view the changes in the Comparison Result dialog box. After you confirm the changes, click Confirm and View. You are returned to the Publish TSL Model dialog box, and the "I have reviewed the comparison between the current version and the online version" check box is automatically selected.

    If you do not need to compare the versions, you can manually select the I have reviewed the comparison between the current version and the online version check box.

  4. Click OK to publish the TSL model.

    After the TSL model is published, you are redirected to the Feature Definition tab of the product details page. You can view the version number and publication time of the published TSL model.

    image.png

Results

After the TSL model is published, IoT Platform generates a published version of the TSL model for the product. On the Feature Definition tab of the Product Details page, you can perform the following operations:

  • Click TSL Model to view the TSL model in JSON format.

  • Click Generate Device-side Code to download the device-side code that IoT Platform generates based on the features you defined. Use this code for device-side development.

Important

This feature is supported only by legacy public instances in the China (Shanghai) region. For more information about instances, see Instance overview.

Related APIs

API

Description

UpdateThingModel

Updates a single feature in a product's TSL model. You can also use this operation to update the extended description of the TSL model.

QueryThingModel

Queries the details of feature definitions in a product's TSL model.

CopyThingModel

Copies the TSL model from a specified product to a destination product.

PublishThingModel

Publishes the TSL model of a specified product.

ImportThingModelTsl

Imports a TSL file for a specified product. This operation does not support extended description configurations.

QueryThingModelPublished

Queries the details of feature definitions in the published TSL model of a specified product.

What to do next

By default, TSL model data reported by devices is automatically stored in hot data storage. You can disable data storage for some or all TSL model data based on your requirements. For more information, see Disable or enable data storage for a TSL model.

Related documents