Updated on 2022-02-24 GMT+08:00

Rules

Description

The rule engine function allows you to set rules for devices connected to the IoT platform. If the conditions set in a rule are met, the IoT platform triggers the corresponding action. Device linkage and data forwarding rules can be created.

Device linkage rule

Device linkage is triggered by condition. Based on preset rules, the IoT platform triggers collaborative response of multiple devices to implement device linkage and intelligent control. If Topic notification is selected for Action Type in a rule, the IoT platform works with the Simple Message Notification (SMN) service of HUAWEI CLOUD to set and deliver topic notification messages.

For example, when the battery level of a water meter is less than or equal to 20%, a low-battery alarm is reported. In this way, you can replace the battery in time.

Data forwarding rule

Data forwarding works with other HUAWEI CLOUD services to implement on-demand forwarding and processing of device data. You do not need to purchase servers to store, calculate, and analyze device data.
  • Works with Data Ingestion Service (DIS) (available soon) to enable efficient data collection, transmission, and distribution. You can download data by using the SDKs or APIs provided by DIS. You can also use dump tasks to forward data to Object Storage Service (OBS), MapReduce, Data Warehouse Service (DWS), and Data Lake Insight (DLI) for subsequent data processing, such as data storage and analysis.
  • Works with DMS to provide message queues for device data. DMS is a message middleware service based on distributed, highly available clusters. The IoT platform functions as a producer to send messages to the DMS message queue. Your applications consume messages from the message queue. In this way, messages can be transmitted between multiple application components.
  • Works with OBS to persistently store device data. (The IoT platform can store device data for 7 days). OBS is an object-based massive storage service that provides massive, secure, reliable, and low-cost data storage capabilities. It can archive, back up, and store data reported by devices. OBS can work with Cloud Stream (CS, available soon) to analyze data flows in real time. The analysis result is used for data visualization for other cloud services or third-party applications.
  • Works with the Message Queue Service (MQS) component of ROMA – Enterprise Business Integration Platform (available soon) to provide a secure, standard message channel between the IoT platform and NAs. MQS is enterprise-level message middleware that uses Kafka and a unified message access mechanism. It provides basic and advanced functions to offer a unified message channel for enterprise data management. The basic functions include message publishing and subscription, topic management, user permission management, resource statistics, monitoring and alarming. The advanced functions include message tracking, network isolation, and integration of cloud and on-premises applications.

Creating a Device Linkage Rule

  1. Click Create in the upper right corner, and click Device Linkage in the dialog box displayed.
  2. Set the parameters based on Table 1.

    Table 1 Device linkage rule parameters

    Parameter

    Description

    Example Value

    Rule Name

    Name of a rule to be created.

    Create a rule as follows:

    • Rule Name: test
    • Activate Now: Yes
    • Validity Period: Always
    • Device Behavior: Water meter temperature reaching 35°C
    • Send Notification or Alarm: major alarm

    After the rule is created, a major alarm is reported when the temperature of the water meter reaches 35°C.

    Activate Now

    Whether the rule is triggered immediately if the last data reported before the rule creation meets the condition.
    • Yes: After a rule is created, the rule takes effect immediately. The IoT platform checks the last reported data to determine whether to trigger the rule.

    • No: After a rule is created, the IoT platform checks only subsequently reported data to determine whether to trigger the rule.

    Rule Type

    Cloud Rule: a rule for devices that are directly connected to the cloud IoT platform

    Edge Rule: a rule for devices that access the cloud IoT platform through edge nodes

    Edge Node

    This parameter is available when Rule Type is set to Edge rule. Select the edge node to which the rule applies.

    Validity Period

    • Always: There is no time limit. The IoT platform always checks whether conditions are met.
    • Custom: You can select a time segment during which the IoT platform checks whether conditions are met.

    If

    Device Behavior: You can click Add to add a device, device type, or device group as a condition.
    • Condition Type
      • Device: Data that meets the conditions is reported by a device.
      • Device type: Data that meets the conditions is reported by devices of the specified type.
      • Device group: Data that meets the conditions is reported by devices in the specified group.
    • Select Device Model: Select the model of the device that reports the data meeting the conditions. After selecting a device model, select the corresponding service type and set the data reporting rule.
    • Data Validity Period (s): For example, when Data Validity Period is set to 30 minutes, a device generates data at 19:00, and the IoT platform receives the data at 20:00, the action is not triggered regardless of whether the conditions are met.
    • Delay (min): delay for triggering an action after the condition is met. The default value is 0. For example, an alarm indicating an unlocked door is triggered when the door status sensor is turned on. Upon detecting that the door status sensor is activated, an alarm is generated immediately if the default value is used.
    Time: Click Add to set the time at which the rule is triggered. It is usually used for periodic triggering conditions, such as turning off street lamps at 07:00 every day.
    • Start Time: start time for triggering a rule.
    • Repeated Triggering Attempts: number of times that the rule can be triggered. The value ranges from 1 to 1440.
    • Interval (min): interval for triggering the rule after the start time. The value ranges from 1 to 1440.

    Then

    Device Behavior: You can click Add to add the action to be triggered if the conditions are met.

    • Action Type: type of an action. The default value is Device, indicating that a command is issued to a device.
    • Select Device Model: Select the device model corresponding to the action and the device that executes the action in the model. After selecting a device model, select the corresponding service type.
    • Command Status: whether the action is valid. The default value is Enabled.
      • Enabled: The action is valid. The action is executed when the condition is met.
      • Disabled: The action is invalid. The action is not executed when the condition is met.
    • Command Request ID: ID of the command to be delivered.
    • Callback URL: URL to receive a notification if the command status changes, such as failed, successful, timed-out, sent, or delivered.
    • Command Expiration (s): validity period of a command, in units of seconds. If Command Expiration is set to 0, the command is delivered immediately. If Command Expiration is set to other values, the command is cached before being delivered. If Command Expiration is not carried, the default value (48 hours) is used.

    Send Message or Alarm: You can click Add to set a theme notification or event alarm.

    1. Theme notification: You must enable SMN before configuring the theme content on this page.
      1. Choose System Management > Cloud Service Configuration to configure connection with HUAWEI CLOUD. For details, see Cloud Service Configuration.
      2. On the current page, click the SMN link and go to the HUAWEI CLOUD website to enable SMN.
      3. On the current page, select the region where SMN is located, select the theme name, and set the message title and message content.
    2. Event alarm: Define the alarm type, alarm severity, alarm name, and alarm content. If the conditions are met, an alarm is displayed on the Alarms page.
      NOTE:

      If Event alarm is selected, Time under If cannot be specified.

    Description

    Description of the rule.

  3. Click Submit.

    The newly created rule is in the activated state by default. You can disable a rule in the Status column on the rule list.

Creating a Data Forwarding Rule

  1. Click Create Rule in the upper right corner, and click Data Forwarding in the dialog box displayed.
  2. Set the parameters based on Table 2.

    Table 2 Data forwarding rule parameters

    Parameter

    Description

    Example

    Rule Name

    Name of a rule to be created.

    Create a rule as follows:

    • Rule Name: test
    • Object Type: All devices
    • Action Type: DIS
    • Region: cn-north-1
    • Channel: dis-DMPLiteTest
    • Data Type: JSON

    After the rule is created, the IoT platform forwards data in JSON format to DIS in cn-north-1 through dis-DMPLiteTest.

    If

    • Object Type: Select All devices (only data forwarding for all devices is supported).
    • Add Filter. By default, the function is disabled. If the function is enabled, you must specify Property Name, Operate, and Value. The IoT platform forwards the packets that meet the filter criteria. For details, see the data forwarding example.

    Then

    • Action Type: The value can be DIS (available soon), DMS, OBS, or ROMA (available soon).
      NOTE:

      If you have not enabled the service, perform the following steps:

      1. Choose System Management > Cloud Service Configuration to configure connection with HUAWEI CLOUD. For details, see Cloud Service Configuration.
      2. On the current page, click a service link to go to the HUAWEI CLOUD website to enable the service.
        • DMS (available soon): Data can be forwarded to common queues and advanced queues that support logical multi-tenant. Data forwarding to RabbitMQ instances with physical multi-tenant and Kafka instances is not supported.
        • ROMA (available soon): You must subscribe to ROMA and configure the connection with ROMA by following the instructions provided in Subscription to Push Service (ROMA).
    • Forward To: On the page (shown in #EN-US_TOPIC_0172036536__li1324241203120) for creating a data forwarding rule, select the region, channel, data type, and other information of the service to be forwarded.

    Description

    Description of the rule.

    • Data forwarding example:

      The IoT platform parses and matches device data in JSON format after encoding and decoding.

      {
             "deviceId": "6543214c-72bb-4131-9e14-fad974123456",
             "services": [{
                    "serviceId": "serviceId1",
                    "data": {
                           "property1": "reportValue1",
                           "property2": "reportValue2",
                           "property3": "reportValue3"
                    },
                    "eventTime": "20190425T021157Z"
             }]
      }
      Adding filter criteria for data forwarding
      • Filter data based on deviceId and forwards data of a device

      • Filter data based on the service ID or property1/property2/property3 to forward batch device data.

    • Data forwarding rule

  3. Click Submit.

    The newly created rule is in the activated state by default. You can disable a rule in the Status column on the rule list.

Comparison of Data Forwarding Solutions

In many scenarios, you need to process data reported by devices to the IoT platform or use the data for service applications. The IoT platform provides the subscription push and rule engine data forwarding functions to forward device data.

  • The rule engine data forwarding function provides basic data filtering capabilities. It enables the IoT platform to filter device data and forward data to other HUAWEI CLOUD services.
  • Subscription push: An NA can subscribe to service data of a device on the IoT platform. When the service data changes (for example, the device is registered, the device reports data, and the device status changes), the IoT platform can push a change notification to the NA. Device messages can be quickly obtained and no data filtering is available. The function is simple but easy to use and efficient.

    Solution

    Application Scenario

    Advantages and Disadvantages

    Data forwarding rule

    • Reported device data to the cloud
    • Complicated scenario

    Advantages:

    • Forwards data to other HUAWEI CLOUD services.
    • Filters data based on conditions.

    Disadvantages:

    Only data reported by devices can be forwarded. Data about device registration and device status change cannot be forwarded.

    Subscription and push

    • Device data to NAs
    • Device data receipt

    Advantages:

    • Device registration, device data reporting, and device status change can be pushed to NAs.

    Disadvantages:

    • No filtering.
    • NAs need to implement operations such as storage and analysis of pushed data and cannot use other HUAWEI CLOUD services.

    The IoT platform provides only weak HTTP push capabilities. Data forwarding rules are recommended for push messages higher than 10 TPS.