Help Center> IoT Device Access> Best Practices> Device Linkage> Automatic Device Shutdown Upon High Temperature

Automatic Device Shutdown Upon High Temperature

Scenarios

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.

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.

Configuring IoT Device Access

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.

  1. Log in to the IoTDA console.
  2. On the navigation pane, click Products. Click the drop-down list box above the product list, and select the resource space to which the new product belongs.

    Note: The product model and device used in this document are only examples. You can use your own product model and device.

  3. Click Create Product in the upper right corner to create a product using MQTT. Set the parameters and click Create.

    Set Basic Info

    Product Name

    Enter a value, for example, MQTT_Device.

    Protocol

    Select MQTT.

    Data Type

    Select JSON.

    Manufacturer

    Customize the value.

    Define Product Model

    Product Model

    For details about how to import a model, see 5.

    Industry

    Set the parameters as required.

    Device Type

  4. Click Profile.zip to download a sample product model.
  5. On the Model Definition tab page, click Import Local Profile. In the dialog box displayed, upload the product model and click OK.

  6. In the navigation pane, choose Devices > All Devices. On the page displayed, click Individual Register in the upper right corner. On the page displayed, set device registration parameters and click OK.

    Parameter

    Description

    Product

    Select the product created in 3.

    Node ID

    Specify a unique physical identifier for the device, such as its IMEI or MAC address. This parameter is used by the platform to authenticate the device during device access.

    • For a native MQTT device, set the node ID to a string consisting of letters and numbers. The device ID (corresponding to the node ID) and secret generated after the registration are used for device access.
    • For an NB-IoT device (device using LwM2M over CoAP) or a device integrated with the SDK, set the node ID to the IMEI or MAC address. The device connects to the platform using the node ID and secret entered during registration.

    Indicates the 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.

  7. In the navigation pane, choose Rules > Device Linkage, and click Create Rule in the upper right corner.
  8. 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.

    Parameter

    Description

    Rule Name

    Specify the name of the rule to be created, for example, Overheated.

    Activate Now

    Select Activate Now.

    When Effective

    Select Always effective.

    Item

    Provide a description of the rule, for example, "The device is automatically shut down when the device temperature is higher than 80°C."

    Set Trigger Conditions

    1. Click Add Condition.
    2. Select Triggered upon specified device.
    3. Select the device added in 6.
    4. Select tempSensor for Service Type, temperature for Property, > for Operation, and 80 for Value. Click Trigger Mode. In the dialog box displayed, set Trigger Suppression to Yes and Data Validity Period (s) to 300, click OK.

    Set Actions

    1. Click Add Action.
    2. Select Deliver Commands, and select the device created in 6.
    3. Select deviceSwitch for Service Type, and ON_OFF for Command. Click Configure Parameter. In the dialog box displayed, set power to off, 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 {deviceId} with the actual device ID) and report data whose temperature is greater than 80. For details, see Connecting MQTT Devices.

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.