Before you can collect sensor data, you must configure products, devices, communication topics, and data forwarding rules in IoT Platform. This topic uses a handheld infrared thermometer as an example to demonstrate the cloud-side configuration.
Background
A product is a collection of devices of the same type. All devices under a product share the same features. This lets you manage devices in batches, such as defining a Thing Specification Language model or creating custom topics.
Each actual device must correspond to a device in IoT Platform. You must burn the device certificate (ProductKey, DeviceName, and DeviceSecret) issued by IoT Platform onto the device for identity verification when the device connects to IoT Platform. For more information, see Obtain a device certificate.
Procedure
Log on 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.
- Create a product for the handheld infrared thermometer.
- In the left-side navigation pane, choose .
- On the Products page, click Create Product.
- Configure the parameters.
For Node Type, select direct-connected device. For data format, select ICA Standard Data Format (Alink JSON). For more information about other parameters, see Create a product.
- Click Confirm.
- Define a communication topic.
- In the product list, find the product and click View in the Actions column. On the Product Details page, click the Topic Categories tab and then the Custom Topics tab.
- Click Define Topic Class to add a topic for data transmission.
The format of the custom topic is
/{ProductKey}/${deviceName}/user/data. Set Operation Permission to Publish and enter Report raw temperature data for the description.
- Add a device.
- On the Product Details page, click Manage next to Number of Devices.
- On the Devices page, click Add Device.
- In the Add Device dialog box, enter a device name (DeviceName) and a nickname, and then click Confirm.
After the device is created, click View or Copy Device Certificate in the Added dialog box to obtain the device certificate.
The device certificate includes the ProductKey, DeviceName, and DeviceSecret. This certificate is crucial for all future communication between the device and IoT Platform, so store it securely.
- In the device list, find the device and click View to open its Device Details page. On this page, click Edit next to Tag Information to configure the device tags.
In the Edit Tags dialog box, configure location and device tags. For example, set
areato East China,provinceto Zhejiang,cityto Hangzhou, anddistrictto Binjiang, and then click Confirm.
- Create an AMQP server-side subscription consumer group.
After a device connects to IoT Platform, it reports data directly to the platform. You can use a data forwarding rule to send this data from IoT Platform to your server over an AMQP channel. In this step, you create the AMQP server-side subscription consumer group required to configure a Data Forwarding rule in the next step.
- In the left-side navigation pane, choose , and then click Consumer Group List.
- Click Create Consumer Group. For Consumer Group Name, enter Handheld Thermometer Data Consumer Group, and then click OK.
- Configure a Data Forwarding rule.
The rule engine processes data reported by the sensor device and forwards it to the consumer group on your business server.
- In the left-side navigation pane, choose .
- On the Data Forwarding page, click Create Rule.
Important If the new version of the UI is displayed, click Return to Previous Version in the upper-right corner to return to the previous version, and then click Create Rule.
- Configure the parameters.
Set Data Format to JSON. For Rule Name, enter Handheld Thermometer Forwarding.
- Click Confirm. You are redirected to the Data Forwarding Rule page.
- On the Data Forwarding Rule page, click Write SQL, configure the settings, and then click OK.
For Fields, configure the following SQL statement:
For Topic, set Type to Custom, Product to Handheld Infrared Thermometer, Device to All devices (+), and Topic to user/data.SELECT temperature,deviceName() as deviceName, timestamp('yyyy-MM-dd HH:mm:ss') as time, attribute('province') as province, attribute('city') as city, attribute('district') as district, attribute('area') as area FROM "/a1*********/+/user/data" - On the Data Forwarding Rule page, click Add Operation to add an operation that forwards data to the AMQP server-side subscription consumer group you created, and then click OK.
For Select Operation, select Publish to an AMQP consumer group. For Consumer Group, select Handheld Thermometer Data Consumer Group.The rule engine is now configured. The final rule is configured as follows: The Data Format is JSON, the SQL query is set in the Data Processing section, and the operation in the Data Forwarding section forwards data to the AMQP server-side subscription consumer group named Handheld Thermometer Data Consumer Group.
- Return to the Data Forwarding page and click Start to activate the rule.