Device communication using TSL models
IoT Platform lets you define device features by using Thing Specification Language (TSL) models. Devices communicate with IoT Platform through TSL model topics and the Alink JSON data format. This topic covers TSL-based device-platform communication across common scenarios.
Background information
-
For information about defining and using TSL model features, see What is a TSL model?.
-
For information about TSL model communication topics, see What is a topic? and Use topics for communication.
-
For information about the Alink JSON format and topics used for TSL model communication, see Device properties, events, and services and Desired property values of devices.
Benefits
TSL models are a core feature of IoT Platform. Key benefits of TSL model communication:
-
Structured data storage: Simplifies subsequent data development.
-
State caching (device shadows): Query device status and data from the client or server side at any time.
-
Data visualization: View data directly in the IoT Platform console.
-
Online debugging: Debug device properties, events, and services online.
Configure TSL model features
Server-side configuration
Before a device can use a TSL model for communication, complete the following steps in IoT Platform:
-
Create a product: Create a product for the device in the IoT Platform console.
-
Add a single TSL model or Add TSL models in batches: Add properties, events, or services to the TSL model for the product.
-
Register a device: If the device uses per-device or per-product pre-registration for authentication, you must first register the device in IoT Platform to obtain a device certificate (ProductKey, DeviceName, and DeviceSecret).
-
Parse TSL model messages: If the device message format is not Alink JSON, you must use message parsing to convert data from the custom format reported by the device into the Alink JSON format. You must also convert data from the Alink JSON format sent by IoT Platform into the custom format of the device.
-
Server-side subscription and Data forwarding: To forward TSL model data reported by devices — along with responses to property settings and service invocations — to your server or other Alibaba Cloud products for storage and processing, use the data forwarding feature.
For information about the data forwarding format, see Data format.
Device-side configuration
Develop TSL model features on the device so it can report properties and events, and accept instructions from IoT Platform to set properties and invoke services.
IoT Platform provides Link SDKs that help devices quickly connect to Alibaba Cloud IoT Platform. For more information, see Device connection overview.
Link SDKs are available in multiple languages, including C, Java, Python, Node.js, Android, and iOS. Select an SDK that suits your development scenario.
To add a custom TSL model module to a product for communication, you must use the C Link SDK V4.x for device development. For TSL model development sample code, see Examples.
|
Development language |
Link SDK usage example |
|
C Link SDK Extended |
|
|
C (V4.x) |
|
|
C (V3.x) |
|
|
Android |
|
|
Java |
|
|
Python |
|
|
Node.js |
|
|
iOS |
Not supported |
TSL model communication flow
When a device communicates with IoT Platform by using a custom TSL model module, feature fields in the data must include the custom module identifier. The required format is ModuleIdentifier:FeatureIdentifier, where the identifiers are separated by a colon (:).
For example, if the custom module identifier is {tsl.functionBlockId}, the feature identifiers in the communication data use the following format:
-
Property:
{tsl.functionBlockId}:{tsl.properties.identifier}. -
Event:
{tsl.functionBlockId}:{tsl.event.identifier}. -
Service:
{tsl.functionBlockId}:{tsl.service.identifier}.
-
Device reports data: The device generates and reports Alink JSON data based on the Alink protocol format.
If the device message format is not Alink JSON, the data is converted to Alink JSON based on the configured message parsing rules.
-
IoT Platform validates data: IoT Platform validates the property, event, and service invocation data (service request parameters and service invocation results) reported by a device. You can view the validated data on the TSL Model Data tab of the Device Details page in the IoT Platform console.
-
Message forwarding flow: If the device is configured to forward TSL model messages to a business server or other cloud products, the data is forwarded in the specified data format.
On the IoT Platform Logs tab in the IoT Platform console, you can copy the
messageIDortraceIDof a message to trace its full path within IoT Platform and quickly locate faults. For more information, see Message Trace.
TSL model data storage
By default, TSL model data reported by devices is automatically written to time series data storage. You can configure the following storage options:
-
Disable TSL model data storage: Manually disable time series data storage for some or all TSL models of a product.
-
-
For Enterprise instances created after December 1, 2022, the default retention period is 365 days. For instances created before December 1, 2022, the default is 30 days. The default retention period for new public instances is 30 days.
-
The minimum retention period is 7 days. Set the value to -1 for permanent retention. When the retention period expires or storage space is exhausted, IoT Platform deletes the oldest data.
-
Related APIs
IoT Platform provides cloud APIs for managing and using TSL models. For more information, see TSL model management APIs and TSL model usage APIs.
Examples
FAQ
-
How do I store data reported by a device to IoT Platform in a database (MySQL, SQL Server)?
-
Is there a quick way to import custom TSL model features for a product?
-
What do I do if TSL validation fails when I import TSL models in batches?
-
Why is the TSL model data not updated after I report data using a custom topic?
-
Why does the IoT Platform console not display the TSL model data reported by a device?