Monitoring Device Status Changes and Sending Notifications
Introduction
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 Scenario
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.
The procedure is as follows:
- 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.
- Configure Simple Message Notification (SMN). Create an SMS or email subscription.
- 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 are only examples. You can use your own product model and device.
- Visit the IoTDA service page and click Access Console. Click the target instance card.
- 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
- Click here to download a sample product model.
- Click the created product. The product details page is displayed.
- On the Basic Information tab page, click Import from Local. In the dialog box displayed, load the local product model and click OK.
Figure 2 Uploading a model file
- In the navigation pane, choose Devices > All Devices. On the displayed page, click Register Device. On the displayed page, set device registration parameters. Click OK. Save the device ID and secret returned after the registration is successful.
Figure 3 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.
- 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.)
- 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
- Click Add Trigger.
- Select Device Property.
- Select the MQTT_Device product created in 4, select All Devices, and select Offline as the trigger status.
- Set Duration to 5 minutes.
Set Actions
- Click Add Action.
- Select Report alarms.
- 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 4 Creating a linkage rule - GatewayOffline
- Create a linkage rule for alarm clearance.
Figure 5 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.
- Log in to Huawei Cloud and access Simple Message Notification (SMN).
- Click Access Console. If you have not subscribed to SMN, subscribe to it first.
- Choose Create Topic. , and click
- Enter a topic name, for example, Test_1, and click OK.
Figure 6 Creating a topic - SMN
- Choose Add Subscription. , and click
- Enter the subscription information. Click OK.
Figure 7 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.
- Log in to Huawei Cloud and visit AOM.
- Click Try Free to access the AOM console. If you have not subscribed to AOM, subscribe to it first.
- Choose Create. and click
- 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 8 Creating an action rule - AOM
- Choose Create Alarm Rule. and click
- 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 9 Creating an alarm rule - AOM
Verifying Configurations
- You can use a registered physical device to access the platform.
- You can also use a simulator to simulate a device going online and offline. For details, see Developing an MQTT-based Simulated Smart Street Light Online.
Expected result:
- After the device is offline for 5 minutes:
- In the navigation pane, choose Figure 10 Current alarms - Going to AOM
. Click Application Operations Management (AOM) to go to the AOM console. A major GatewayStatusChange alarm is generated.
- 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.
- In the navigation pane, choose
- 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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot