Tutorial: Create a rule and set up notifications in your Azure IoT Central application for the STM32U5 board.
Tutorial: Create a rule and set up notifications in your Azure IoT Central application for the STM32U5 Board
Introduction:In this article, we use Azure IoT Central to monitor the telemetry sent by a device and create a rule that automatically invokes an action, such as sending an email. Devices use telemetry to send numerical data from the device. A rule triggers when the selected telemetry crosses a specified threshold. The board we use is a B-U585I-IOT20A board. It provides functionalities such as a temperature and humidity sensor (highlighted in red) as well as a low power microcontroller and other sensors such as a magnetometer, accelerometer, gyroscope, pressure, Time-of-Flight, and gesture-detection. It also provides a Wi-Fi module, which allows us to connect it to Azure IoT Central.The board can be purchased here .In this tutorial, you create a rule to send an email when the temperature read by the temperature sensor exceeds 20°C.In this tutorial, you learn how to:
- Create a rule
- Add an email action
Requirements:
- Subscribe to an active Azure account (link for Microsoft account)
- Download the azure package from here
- Refer to this article to install the package and provision the board
After going through the article, you should have:
- An IoT Central application where you can monitor telemetry sent by the STM32U5 board
- On the left pane of your application in IoT central, click on Device templates. You should see the B-U585I-IOT20A device template.
Create a rule
To create a telemetry rule, the device template must include at least one telemetry value. This tutorial uses the B-U585I-IOT20A board that sends temperature telemetry. The rule monitors the temperature reported by the device and sends an email when it goes above 20-degree Celsius. Note: There is a limit of 50 rules per application.
- In the left pane, select Rules.
- If you have not created any rules yet, you see the following screen:
- Select + New to add a new rule.
- Enter the name Temperature monitor to identify the rule and press Enter.
- Select the B-U585I-IOT20A device template.
Configure the rule conditions
Conditions define the criteria that the rule monitors. In this tutorial, you configure the rule to fire when the temperature exceeds 20° C.
- Select Temperature in the Telemetry dropdown.
- Next, choose Is greater than as the Operator and enter 20 as the Value.
Choose an aggregation type, such as average or sum, from the aggregation drop-down menu when you choose a time aggregation.
-
- The rule executes for every telemetry data point that satisfies the requirement without any aggregation. For instance, if you set the rule to activate when the temperature rises over 20, the device temperature will nearly immediately cause the rule to activate.
- If the requirement is met using aggregation, the rule is activated if the total value of the telemetry data points inside the time span. If the rule conditions are set to trigger when the average temperature is greater than 20 in the span of 10 minute, the rule will fire only once every 10 minutes.
You can add multiple conditions to a rule by selecting + Condition. When multiple conditions are added, you can specify if all the conditions must be met or any of the conditions must be met for the rule to trigger. If you are using time aggregation with multiple conditions, all the telemetry values must be aggregated.
Configure actions
After you define the condition, you set up the actions to take when the rule fires. Actions are invoked when all the conditions specified in the rule are evaluated to be true.
- Select + Email in the Actions section.
- Enter Temperature warning as the display name for the action, your email address in the To field.
Note: Emails are only sent to the users that have been added to the application and have logged in at least once.
- Go to Security in the left pane
- Select Permissions
- In Users under Permissions, click on +Assign user
- Add your email id where you would like to receive the trigger emails
- Under Role, select App Operator
- Click on Save
- After a while, you receive an email message when the rule fires:
Delete a rule
If you no longer need a rule, delete it by opening the rule and choosing Delete.
Enable or disable a rule
Choose the rule that you want to enable or disable. Toggle the Enabled/Disabled button in the rule to enable or disable the rule for all devices that are scoped in the rule.