Define a TSL model

更新时间:
复制 MD 格式

In IoT Platform, you can define a Thing Specification Language (TSL) model for a product. A tsl model abstracts a physical product into a data model that consists of properties, services, and events. This model lets IoT Platform manage and interact with devices. After you create a product, you can define its tsl model. Devices that belong to the product automatically inherit the tsl model.

Prerequisites

You have created a product. For more information, see Create a product and a device.

Background

This topic uses a street lamp to demonstrate how to define two properties for a product: Main Light Switch and Current. After you define the tsl model, you can connect multiple street lamp devices to the product. Each device automatically inherits the defined tsl model. To learn more about tsl models, see What is a tsl model?.

Procedure

  1. Log on to the IoT Platform console.

  2. On the Overview tab, click Public Instance.

  3. In the left-side navigation pane, choose Devices > Products. On the Products page, find the street lamp product that you created and click View in the Actions column.

  4. On the Product Details page, click the Define Feature tab, and then click Edit Draft.

  5. On the Edit Draft page, in the Default Module section, click Add Self-defined Feature to configure the tsl model, then click OK.

    Configure the Main Light Switch and Current properties for the street lamp product.

    • Configure the Main Light Switch property: set Feature Type to Property, enter Main Light Switch for Feature Name, enter LightSwitch for Identifier, select bool for Data Type (0 for Off, 1 for On), and select read/write for Read/Write Type.

    • Configure the Current property: set Feature Type to Property, enter Current for Feature Name, enter LightCurrent for Identifier, select float for Data Type, set the value range to 0 to 9, set the step to 0.1, select Ampere / A as the unit, select read-only for Read/Write Type, and enter "Electrical parameters use 4-byte floating-point data." for Description.

  6. (Optional) Click TSL Model. On the Full TSL tab, you can view the complete tsl model for the product in JSON format.

    The JSON file includes the schema, profile, and properties arrays. For example, the LightSwitch (Main Light Switch) property uses the bool data type and the rw (read/write) access mode. A value of 0 indicates Off and 1 indicates On. In the lower-right corner, click Export Model File to export the tsl model to a local file.

  7. 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 Define Feature, click Publish. The Publish TSL Model? dialog box appears.

    2. Click Add Publication Note and enter a version number and a version 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 a version is already published, you must compare the draft with the published 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.

Next steps

Connect a device to IoT Platform