Help Center> IoT Device Access> Best Practices> Device Linkage> Automatically Opening the Window upon High Gas Concentration

Automatically Opening the Window upon High Gas Concentration

Scenarios

IoTDA can instruct a wireless window opener to open the window through a device linkage rule. The scenario is as follows: A gas detector reports the gas concentration value to the IoT platform. When the gas concentration exceeds a specific threshold, the preset device linkage rule is triggered. The platform delivers a window opening command to the wireless window opener, which then opens the window as instructed.

Creating a Gas Monitoring Product

  1. Log in to the IoTDA console.
  2. In 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.
  3. Click Create Product in the upper right corner to create a gas monitoring product, set the parameters, and click Create.

    Set Basic Info

    Product Name

    Enter a value, for example, gasdevice.

    Protocol

    Select MQTT.

    Data Type

    Select JSON.

    Manufacturer

    Customize the value.

    Define Product Model

    Product Model

    Not selected

    Industry

    Customize the values.

    Device Type

  4. On the Model Definition tab page, click Custom Model and configure the product model based on the table below.

    Service data

    Service

      

    Service: gaslevel

      

    Properties

    Property Name: gaslevel

    Mandatory: selected

    Data Type: int

    Access Permissions: Read

    Value range: 0-100

      

    Commands

    Command Name: switch

    Parameter Name: switch

    Mandatory: selected

    Data Type: string

    Length: 1

    Enumerated Values: on,off

Registering a Device

  1. 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. Register the gas monitoring device and record the device ID and secret.

    Parameter

    Description

    Product

    Select the product created in 4.

    Node ID

    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.

    Device Name

    The name can be customized.

    Authentication Type

    Select Secret.

    Secret

    Customize the secret used for device access. If no secret is specified, the platform automatically generates a secret.

  2. 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. Register a window opener device and record the device ID and secret.

    Parameter

    Description

    Product

    Select the product created in 4.

    Node ID

    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.

    Device Name

    The name can be customized.

    Authentication Type

    Select Secret.

    Secret

    Customize the secret used for device access. If no secret is specified, the platform automatically generates a secret.

Configuring a Device Linkage Rule

  1. In the navigation pane, choose Rules > Device Linkage, and click Create Rule in the upper right corner.
  2. 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 create, for example, windowswitch.

    Activate Now

    Select Activate Now.

    When Effective

    Select Always effective.

    Description

    Enter a description of the rule, for example, "Automatically opens the window when the gas concentration is higher than 6".

    Set Trigger Conditions

    1. Click Add Condition.
    2. Select Triggered upon specified device.
    3. Select the device added in 1.
    4. Select gaslevel for Service Type, gaslevel for Property, > for Operation, and 6 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 2.
    3. Select windowswitch for Service Type, and on_off for Command. Click Configure Parameter. In the dialog box displayed, set switch to on, click OK.

Verifying the Configurations

Method 1:

You can use MQTT.fx to simulate device verification.

  1. Use MQTT.fx to simulate a gas detector and a window opener, and connect them to the platform. For details, see Using MQTT.fx to Experience Device Access.
  2. Open MQTT.fx that simulates the window opener to subscribe to commands delivered by the platform.
    1. Click the Subscribe tab.
    2. Enter Topic=$oc/devices/{device_id}/sys/commands/# of the command delivered by the subscription platform. (The value must be the same as the device ID obtained in 2.)
    3. Click Subscribe to deliver the subscription.

  3. Switch to MQTT.fx that simulates the gas detector to report properties.
    1. Click the Publish tab.
    2. Enter topic $oc/devices/{device_id}/sys/properties/report for property reporting. ({deviceId} must be the same as the device ID obtained in 1.)
    3. Report the property gaslevel with a value greater than 6.
      Example:
      {
          "services": [{
                  "service_id": "gaslevel",
                  "properties": {
                      "gaslevel": 45
                  }
              }
          ]
      }
    4. Click Publish to report the property value.

  4. Switch to MQTT.fx that simulates the window opener and click the Subscribe tab. The command carrying switch with the value set to on delivered by the platform is received.

    Method 2:

    You can use a registered physical device to access the platform and enable the device to report the gaslevel greater than 6. The device receives a command carrying switch with the value set to on and automatically opens the window.