Help Center> IoT Device Access> Best Practices> Device Linkage> Monitoring Device Status Changes and Sending Notifications
Updated on 2024-04-29 GMT+08:00

Monitoring Device Status Changes and Sending Notifications

Scenarios

Device administrators need to know connection statuses of IoT devices, such as IoT gateways.

IoTDA provides the rule engine function to meet this requirement. You can easily enable the platform to send a notification when the device status meets a certain condition.

Example:

An enterprise has a batch of gateways under a gateway product. About 400 child devices are mounted to a gateway. Administrators need to check gateway statuses in real time to ensure that child devices report data properly. In addition, the gateways are connected to the IoT platform over the 4G network, frequent alarms are generated due to network jitter. Administrators consider that the scenario where devices go offline and quickly go online is normal and do not want to be notified of this scenario.

The following example shows how to monitor all gateways. When a gateway is offline for 5 minutes, an alarm is reported by IoTDA. When the gateway is back to online for 1 minute, the alarm is cleared and an email or SMS is sent to a specified address or mobile number.

Interconnection Process

  1. Configure IoTDA. Create an IoT product and device and create a linkage rule so that alarms can be sent to Application Operations Management (AOM) when device status conditions are met.
  2. Configure Simple Message Notification (SMN). Create an SMS or email subscription.
  3. Configure AOM. Create alarm rules to process alarms reported by IoTDA and send SMS or email notifications using SMN.

Configuring IoTDA

Create a product model, register a device, and configure a device linkage rule on IoTDA. When a device is offline for 5 minutes, an alarm is reported to AOM. This alarm is cleared 1 minute after the device goes online.

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

  1. Visit the IoTDA product page and click Access Console.
  2. Choose Products in the navigation pane and click Create Product on the left to create an MQTT product. Set the parameters and click OK.

    Table 1 Parameters for creating a product

    Basic Information

    Product Name

    Enter a value, for example, MQTT_Device.

    Protocol

    Select MQTT.

    Data Type

    Select JSON.

    Industry

    Set the parameters as required.

    Device Type

  3. Click here to download a sample product model.
  4. Click the created product. The product details page is displayed.
  5. On the Model Definition tab page, click Import from Local. In the dialog box displayed, load the local product model and click OK.

    Figure 1 Uploading a model file

  6. In the navigation pane, choose Devices > All Devices. On the page displayed, click Register Device. On the page displayed, set device registration parameters and click OK. Click OK. Save the device ID and secret returned after the registration is successful.

    Figure 2 Registering a device - gateway
    Table 2 Parameters for registering a device

    Parameter

    Description

    Product

    Select the product created in 4.

    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.

  7. 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.)
  8. Configure rule parameters based on the table below to create a rule for reporting offline gateway alarms. 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.

    Table 3 Parameters for creating a linkage rule

    Parameter

    Description

    Rule Name

    Customize a value, for example, Gateway_Offline_Monitor.

    Activate upon creation

    Select Activate upon creation.

    Effective Period

    Select Always effective.

    Description

    Describe the rule, for example, This alarm is generated when the gateway is offline for 5 minutes.

    Set Triggers

    1. Click Add Trigger.
    2. Select Device Property.
    3. Select the MQTT_Device product created in 4, select All Devices, and select Offline as the trigger status.
    4. Set Duration to 5 minutes.

    Set Actions

    1. Click Add Action.
    2. Select Report alarms.
    3. Set the alarm severity to Major, alarm isolation level to Device, Alarm Name to GatewayStatusChange, and Description to The gateway is offline. Check the issue and arrange personnel for maintenance in a timely manner., and click OK.
    Figure 3 Creating a linkage rule - GatewayOffline

  9. Create a linkage rule for alarm clearance.

    Figure 4 Creating a linkage rule - GatewayOnline
    • The alarm name, alarm severity, and alarm isolation dimension together identify an AOM alarm. The three attributes of the alarm to clear must be the same as those specified during alarm reporting. Otherwise, the alarm clearance will fail.
    • There is a flow control for device status monitoring. If a large number of devices are monitored, flow control is triggered. As a result, alarms cannot be reported. For details, see Limitations.

Configuring SMN

On the Simple Message Notification (SMN) console, create a topic and add a subscription for AOM to invoke to send emails or SMS messages.

  1. Log in to Huawei Cloud and access Simple Message Notification (SMN).
  2. Click Access Console. If you have not subscribed to SMN, subscribe to it first.
  3. Choose Topic Management > Topics, and click Create Topic.
  4. Enter a topic name, for example, Test_1, and click OK.

    Figure 5 Creating a topic - SMN

  5. Choose Topic Management > Subscriptions, and click Add Subscription.
  6. Enter the subscription information. Click OK.

    Figure 6 Adding a subscription - SMN
    Table 4 Parameters for adding a subscription

    Parameter

    Description

    Topic Name

    Select the topic created in 4.

    Protocol

    • To send an email notification, select Email.
    • To send an SMS notification, select SMS.

    Endpoint

    • If Protocol is set to Email, enter the email address for receiving notifications.
    • If Protocol is set to SMS, enter the mobile number for receiving notifications.

    To add multiple endpoints, place one endpoint in a line. A maximum of 10 lines can be entered.

Configuring AOM

Create alarm rules and alarm action rules on AOM. When IoTDA alarms are reported, AOM handles the alarm and sends email or SMS notifications.

  1. Log in to Huawei Cloud and visit AOM.
  2. Click Try Free to access the AOM console. If you have not subscribed to AOM, subscribe to it first.
  3. Choose Alarm Center > Alarm Action Rules and click Create.
  4. Enter an alarm action rule name, for example, Test_1, select the Test_1 topic created in Configuring SMN, and click the button to confirm the setting.

    Figure 7 Creating an action rule - AOM

  5. Choose Alarm Center > Alarm Rules and click Create Alarm Rule.
  6. Enter a rule name, for example, Gateway_Status_Change_Alarm_Rule, select the event alarm and custom event options, enter IoTDA in Alarm Source, set Select Object to event_name=GatewayStatusChange (GatewayStatusChange is the alarm name), set Triggering Policy to Immediate Triggering, set Alarm Mode to Direct Alarm Reporting, set Action Rule to the action rule created in 4, and click Create Now in the lower right corner.

    Figure 8 Creating an alarm rule - AOM

Verifying Configurations

Expected result:

  1. After the device is offline for 5 minutes:
    • In the navigation pane, choose O&M > Device Alarms. Click Application Operations Management (AOM) to go to the AOM console. A major GatewayStatusChange alarm is generated.
      Figure 9 Current alarms - going to AOM
    • If the alarm rule and email notification action are configured in AOM, the target email address will receive an email notifying that the gateway is offline.
    • If the alarm rule and SMS notification action are configured in AOM, the target number will receive an SMS notifying that the gateway is offline.
  2. After the device is back online for 1 minute:
    • The major alarm is cleared. You can view the alarm in the historical alarm list.
    • If the alarm rule and email notification action are configured in AOM, the target email address will receive an email notifying that the gateway goes online.
    • If the alarm rule and SMS notification action are configured in AOM, the target number will receive an SMS notifying that the gateway goes online.