Help Center> IoT Device Access> Best Practices> Device Linkage> Triggering Alarms and Sending Email or SMS Notifications

Triggering Alarms and Sending Email or SMS Notifications

Scenarios

Many IoT devices run 24 hours a day. Device administrators do not need to know the real-time device status. They only need to be notified of certain statuses.

IoT Device Access provides the rule engine function to meet this requirement. You can set rules to enable the platform to send a notification when the data reported by a device meets a certain condition.

In this example, when the battery level reported by the device is lower than 20%, the IoT platform reports an alarm and sends an email or SMS notification to the specified mobile number.

Configuring SMN

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

  1. Log in to HUAWEI CLOUD and access SMN.
  2. Click Access Console. If you have not subscribed to SMN, subscribe to it first.
  3. Choose Topic Management > Topics page, and click Create Topic.
  4. Enter the topic name, for example, Battery_Low_Notify, and click OK.

  5. Choose Topic Management > Subscriptions page, and click Add Subscription.
  6. Enter the subscription data.

    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.

    Click OK.

Configuring IoT Device Access

Using IoT Device Access, you can create a product model, register a device, and set a device linkage rule. When the device reports specific data, an alarm is triggered and an email or SMS notification is sent.

  1. Log in to the IoTDA console.
  2. On 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.

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

  3. Click Create Product in the upper right corner to create a product using MQTT. Set the parameters and click Create.

    Set Basic Info

    Product Name

    Enter a value, for example, MQTT_Device.

    Protocol

    Select MQTT.

    Data Type

    Select JSON.

    Manufacturer

    Customize the value.

    Define Product Model

    Product Model

    For details about how to import a model, see 5.

    Industry

    Set the parameters as required.

    Device Type

  4. Click Profile.zip to download a sample product model.
  5. On the Model Definition tab page, click Import Local Profile. In the dialog box displayed, upload the product model and click OK.

  6. 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.

    Parameter

    Description

    Product

    Select the product created in 3.

    Node ID

    Specify a unique physical identifier for the device, such as its IMEI or MAC address. This parameter is used by the platform to authenticate the device during device access.

    • For a native MQTT device, 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.
    • For an NB-IoT device or a device integrated with the SDK, set the node ID to the IMEI or MAC address. The device connects to the platform using the node ID and secret entered during registration.

    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.

    Click OK. Save the device ID and secret returned after the registration is successful.

  7. In the navigation pane, choose Rules > Device Linkage, and click Create Rule in the upper right corner.
  8. 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

    Enter a name, such as Battery_Low_Mail or Battery_Low_SMS.

    Activate Now

    Select this option.

    When Effective

    Select Always effective.

    Description

    Provide a description of the rule, for example, "When the battery level reported by a device is lower than 20%, an alarm is reported and a notification is sent."

    Set Trigger Conditions

    1. Click Add Condition.
    2. Select Triggered upon specified device.
    3. Select the device added in 6.
    4. Select Battery for Service Type, batteryLevel for Property, < for Operation, and 20 for Value. Click Trigger Mode. In the dialog box displayed, set Trigger Suppression to Yes and Data Validity Period (s) to 3600, click OK.

    Set Actions

    Add an alarm.

    1. Click Add Action.
    2. Select Report alarms.
    3. Set the alarm severity to Minor, Alarm Name to Low battery level, and alarm content to The battery level is lower than 20%. Check and replace the battery in time. Click OK.

    Add a notification.

    1. Click Add Action.
    2. Select Send notifications.
    3. Select the region where SMN is available, for example, cn-north-4. When you create a rule for connecting to SMN for the first time, a cloud service access authorization window will be displayed based on the cloud service to connect and region. Configure cloud service access authorization as prompted. (You can log in to the SMN console and view the information in the upper left corner.)
    4. Select the topic created when configuring SMN for Topic Name.
      • If Protocol corresponding to the topic is Email, set Message Title to an email title, for example, [Huawei IoT Platform] Low Battery Warning, and set Message Content to information similar to You have a device with less than 20% charge, please log in to the Huawei IoT Platform for details.
      • If Protocol corresponding to the topic is SMS, left Message Title unspecified, and set Message Content to information similar to You have a device with less than 20% charge, please log in to the Huawei IoT Platform for details.

Verifying the Configurations

  • You can use a registered physical device to access the platform and enable the device to report the battery level less than 20.
  • You can also use a simulator to simulate a device to report the battery level less than 20. For details, see Connecting MQTT Devices.

Expected result:

  • In the navigation pane on the left, choose Monitoring and O&M > Device Alarms. Click View Alarms to go to the AOM console. A minor alarm is generated indicating that the device battery is low.
  • If you have subscribed to email notification, the mailbox receives an email indicating that the device battery is low.
  • If you have subscribed to SMS notification, the mobile phone receives an SMS notification indicating that the battery level is low.