Help Center> IoT Device Access> Best Practices> Device Linkage> Automatically Opening the Window upon High Gas Concentration
Updated on 2023-04-06 GMT+08:00

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. Visit the IoTDA product page and click Access Console.
  2. In the navigation pane, choose Products.
  3. Click Create Product in the upper right corner to create a gas monitoring product, set the parameters, and click OK.

    Table 1 Parameters for creating a product

    Basic Information

    Product Name

    Enter a value, for example, gasdevice.

    Protocol

    Select MQTT.

    Data Type

    Select JSON.

    Manufacturer

    Customize the value.

    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. The gaslevel service monitors the gas concentration. The windowswitch service executes commands for opening and closing windows.

    Table 2 Parameters of the gas concentration monitoring product model

    Service ID

    Type

    Description

    gaslevel

    Properties

    Property Name: gaslevel

    Data Type: int

    Access Permissions: Read

    Value range: 0–100

    windowswitch

    Commands

    Command Name: switch

    Parameter Name: switch

    Data Type: enum

    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.

    Figure 1 Registering a gas concentration monitoring device
    Table 3 Parameters for registering a device

    Parameter

    Description

    Product

    Select the product created in step 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.

  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.

    Figure 2 Parameters for registering a window opener device
    Table 4 Parameters for registering a device

    Parameter

    Description

    Product

    Select the product created in step 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.

Configuring a Device Linkage Rule

  1. In the navigation pane, choose Rules > Device Linkage, and click Create Rule in the upper right corner. (Before creating a rule, select the resource space to which the rule will belong.)
  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.

    Figure 3 Creating a linkage rule
    Table 5 Parameters for creating a linkage rule

    Parameter

    Description

    Rule Name

    Specify the name of the rule to create, for example, windowswitch.

    Activate upon creation

    Select Activate upon creation.

    Effective Period

    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 Triggers

    1. Click Add Trigger.
    2. Select Device Property.
    3. Select the product added in 3, select Assign Device, and then select the device added in 1.
    4. Select gaslevel for Select service, gaslevel for Select property, > as the operation, and enter 6. 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

    1. Click Add Action.
    2. Select Deliver Commands, and select the device created in 2.
    3. Select windowswitch for Select service, and on_off for Select 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 Developing an MQTT-based Smart Street Light Online.
  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.
      Figure 4 Creating an MQTT 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.
      Figure 5 MQTT property reporting
  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.
    Figure 6 Viewing delivered commands

    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.