Automatic Device Shutdown Upon High Temperature
Introduction
The IoT platform supports device data reporting and command delivery. To associate the two, an application needs to provide corresponding logic.
However, with the rule engine function provided by IoT Device Access, the platform can automatically deliver specified commands when specific data is reported, reducing the application development workload.
Example Scenario
In this example, when the temperature reported by the temperature sensor of a device is higher than 80°C, the IoT platform automatically delivers a command to shut down the device.
The procedure is as follows:
1. IoTDA: Define product models, create devices, and configure linkage rules.
Configuring IoTDA
Using IoT Device Access, you can create a product model, register a device, and set a device linkage rule to enable the IoT platform to send a command when receiving specific data from the device.
- Visit the IoTDA product page and click Access Console. Click the target instance card.
- In the navigation pane, choose Products.
Note: The product model and device used in this document are only examples. You can use your own product model and device.
- Click Create Product to create a product using MQTT. Set the parameters and click OK.
Table 1 Parameters for creating a product Basic Information
Product Name
Enter a value, for example, MQTT_Device.
Protocol
Select MQTT.
Data Type
Select JSON.
Manufacturer
Customize the value.
Industry
Set the parameters as required.
Device Type
- Click Profile_tempSensor.zip to download a sample product model.
- On the Basic Information tab page, click Import from Local. In the displayed dialog box, load the local product model and click OK.
Figure 2 Uploading a model file
- In the navigation pane, choose Devices > All Devices. On the displayed page, click Register Device. On the displayed page, set device registration parameters.
Figure 3 Registering a device - MQTT
Table 2 Parameters for registering a device Parameter
Description
Product
Select the product created in 3.
Node ID
Set this parameter to the IMEI, MAC address, or serial number of the device. If the device is not a physical one, set this parameter to a custom character string that contains letters and digits.
Device Name
Customize the value.
Authentication Type
Select Secret.
Secret
Customize the secret used for device access. If the secret is left blank, the platform automatically generates a secret.
Click OK. Save the device ID and secret returned after the registration is successful.
- In the navigation pane, choose Rules > Device Linkage, and click Create Rule. (Before creating a rule, select the resource space to which the rule will belong.)
- Set the parameters based on the table below. The following parameter values are only examples. You can create your own rules by referring to User Guide. After setting the parameters, click Create Rule.
Figure 4 Creating a linkage rule - TemperatureProperty
Table 3 Parameters for creating a linkage rule Parameter
Description
Rule Name
Specify the name of the rule to be created, for example, Overheated.
Activate upon creation
Select Activate upon creation.
Effective Period
Select Always effective.
Description
Provide a description of the rule, for example, "The device is automatically shut down when the device temperature is higher than 80°C."
Set Triggers
- Click Add Trigger.
- Select Device Property.
- Select the product added in 3, select Assign Device, and then select the device added in 6.
- Select tempSensor for Select service, temperature for Select property, > as the operation, and enter 80. Click Trigger Mode. In the dialog box displayed, set Trigger Strategy to Repetition suppression and Data Validity Period (s) to 300, and click OK.
Set Actions
- Click Add Action.
- Select Deliver commands, and select the device created in 6.
- Select deviceSwitch for Select service, and ON_OFF for Select command. Click Configure Parameter. In the dialog box displayed, set power to OFF, and click OK.
Verifying the Configurations
- You can use a registered physical device to access the platform and enable the device to report the temperature greater than 80.
- You can also use a simulator to simulate a device to subscribe to Topic: $oc/devices/{device_id}/sys/properties/report (replace {device_id} with the actual device ID) and report data whose temperature is greater than 80. For details, see Developing an MQTT-based Simulated Smart Street Light Online.
- You can also use a virtual device for online debugging and enable the device to report the temperature greater than 80.
Expected result:
- If you use a physical device to report data, the device receives an ON_OFF command in which power is OFF.
- If you use a simulator to report data, you can view the ON_OFF command in which power is OFF on the Subscribe tab page.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot