This tutorial explains how to create a temperature sensor product and its devices in IoT Platform, define a TSL model for the product, and create a data forwarding rule to process device data.
Procedure
- Log in to the IoT Platform console.
On the Overview page, find the instance that you want to manage and click the instance ID or instance name.
- In the left-side navigation pane, choose . Click Create Product to create a temperature sensor product. For more information, see Create a product.
Configure the product with the following settings: set Category to Custom Category, Node Type to Directly Connected Device, Networking Method to Wi-Fi, Data Format to ICA Standard Data Format (Alink JSON), and Authentication Method to Device Secret.
- Define a feature.
- On the Product Details page of the product, on the Define Feature tab, choose to define a temperature property.
Set the following parameters: Feature Type to Property, Feature Name to
Temp, Identifier toTemperature, Data Type to double (Double-precision floating-point), Value Range from-50to100, Step to0.1, Unit to Celsius (°C), and Read/Write Type to Read and write. - After you add the feature, click Release to publish the TSL model.
- On the Product Details page of the product, on the Define Feature tab, choose to define a temperature property.
- In the left-side navigation pane, choose Devices and click Add Devices in Batches to create multiple devices.
This example requires 5,000 devices. You can create up to 1,000 devices at a time. Therefore, you must repeat this operation five times. For more information, see Create multiple devices in a batch.
- In the left-side navigation pane, choose . Create a data forwarding rule to forward temperature data reported by the sensors to Function Compute (FC).
- Click Create Rule to create a rule that processes JSON-formatted data.
- Find the rule that you want to manage and click View in the Actions column to go to the rule details page. Then, you can write an SQL expression for data processing.
The SQL expression in this example filters property data that is reported by devices of the temperature sensor product. The SQL expression selects the values of the deviceName and Temperature fields when the reported temperature is higher than 25°C. These values are forwarded to Function Compute.
In the Write SQL section, enterdeviceName() as DeviceName,items.Temperature.valuein the Fields field. In the Topic section, select Submit TSL model data, Temperature Sensor, All Devices(+), and thenthing/event/property/post. In the Condition field, enterTemperature>25. - Set Function Compute as the data destination.
In the Add Operation dialog box, select Forward data to Function Compute (FC) from the Operation drop-down list. Select China (Shanghai) for Region. Select a Service and a Function. Select Default Version for Function Version. Select AliyunIOTAccessingFCRole for Role. If data forwarding fails, the system retries the data forwarding three times at intervals of 1 second, 3 seconds, and 10 seconds. If all the three retries fail, the message is discarded. We recommend that you add an error handling action.
- After the rule is configured, return to the Data Forwarding page and click Start in the Actions column of the rule.
For more information, see Configure a data forwarding rule.
Next steps
该文章对您有帮助吗?