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

Automatically Opening the Window upon High Gas Concentration

Introduction

IoTDA can instruct a wireless window opener to open the window through a device linkage rule.

Example Scenario

In this example, 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.

The procedure is as follows:

1. Create a gas monitoring product.

2. Register the device based on the gas monitoring product.

3. Configure a device linkage rule.

4. Perform verification.

Figure 1 Example

Creating a Gas Monitoring Product

  1. Visit the IoTDA product page and click Access Console. Click the target instance card.
  2. In the navigation pane, choose Products.
  3. Click Create Product on the left 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.

    Industry

    Customize the values.

    Device Type

  4. On the Basic Information tab page, click Customize 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 displayed page, click Register Device. On the displayed page, set device registration parameters. Register the gas monitoring device and record the device ID and secret.

    Figure 2 Registering a device - gasdevice
    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 displayed page, click Register Device. On the displayed page, set device registration parameters. Register a window opener device and record the device ID and secret.

    Figure 3 Registering a device - windowswitch
    Table 4 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.

Configuring a Device Linkage Rule

  1. 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.)
  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 4 Creating a linkage rule - GasLevel
    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 Simulated 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. (Replace {device_id} with the device ID obtained in 2.)
    3. Click Subscribe to deliver the subscription.
      Figure 5 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. (Replace {device_id} with 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 6 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 7 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.