You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/iot-hub/iot-hub-monitoring-notifications-with-azure-logic-apps.md
+88-37Lines changed: 88 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ author: kgremban
7
7
ms.author: kgremban
8
8
ms.service: iot-hub
9
9
ms.topic: tutorial
10
-
ms.date: 02/02/2024
10
+
ms.date: 02/05/2024
11
11
---
12
12
13
13
# Tutorial: Monitor IoT devices and send notifications with Azure Logic Apps
@@ -93,7 +93,13 @@ Create a Service Bus namespace and queue. Later in this article, you create a ro
93
93
94
94
1. In the **Name** field, provide a name for the queue. Accept the default values for the other fields and select **Create**.
95
95
96
-
1. Back on the **Service Bus Namespace** pane, select **Queues** from the **Entities** section of the resource menu. Then, select the queue that you just created from the list
96
+
1. In your Service Bus namespace, select **Shared access policies** from the **Settings** section of the resource menu.
97
+
98
+
1. Select the **RootManageSharedAccessKey** policy to open its details.
99
+
100
+
1. Copy the value of **Primary connection string** and save it to use later in this tutorial when you configure the logic app.
101
+
102
+
<!-- 1. Back on the **Service Bus Namespace** pane, select **Queues** from the **Entities** section of the resource menu. Then, select the queue that you just created from the list
97
103
98
104
:::image type="content" source="./media/iot-hub-monitoring-notifications-with-azure-logic-apps/queues-select-queue.png" alt-text="Screenshot that shows the list of queues in your namespace.":::
99
105
@@ -105,6 +111,10 @@ Create a Service Bus namespace and queue. Later in this article, you create a ro
105
111
106
112
:::image type="content" source="./media/iot-hub-monitoring-notifications-with-azure-logic-apps/add-sas-policy.png" alt-text="Screenshot that shows creating a shared access policy.":::
107
113
114
+
1. After your policy is created, select it from the list of policies to open the details.
115
+
116
+
1. Copy the value of the **Primary connection string** and save it to use later in this tutorial when you configure the logic app. -->
117
+
108
118
## Add a custom endpoint and routing rule to your IoT hub
109
119
110
120
Add a custom endpoint for the Service Bus queue to your IoT hub. Then, create a message routing rule to direct messages that contain a temperature alert to that endpoint, where they will be picked up by your logic app. The routing rule uses a routing query, `temperatureAlert = "true"`, to forward messages based on the value of the `temperatureAlert` application property set by the client code running on the device. To learn more, see [Message routing query based on message properties](./iot-hub-devguide-routing-query-syntax.md#query-based-on-message-properties).
@@ -142,85 +152,115 @@ Add a custom endpoint for the Service Bus queue to your IoT hub. Then, create a
142
152
143
153
1. Select **Create + skip enrichments**.
144
154
145
-
## Create and configure a Logic App
155
+
## Configure Logic Apps for notifications
146
156
147
157
In the preceding section, you set up your IoT hub to route messages containing a temperature alert to your Service Bus queue. Now, you set up a logic app to monitor the Service Bus queue and send an e-mail notification whenever a message is added to the queue.
148
158
149
159
### Create a logic app
150
160
151
-
1.Select **Create a resource** > **Integration** > **Logic App**.
161
+
1.In the Azure portal, search for and select **Logic Apps**.
152
162
153
-
1.Enter the following information:
163
+
1.Select **Add** to create a new logic app.
154
164
155
-
**Name**: The name of the logic app.
165
+
1. Enter the following information on the **Basics** tab of **Create Logic App**:
156
166
157
-
**Resource group**: Use the same resource group that your IoT hub uses.
167
+
| Parameter | Value |
168
+
| --------- | ----- |
169
+
|**Resource group**| Select the same resource group that contains your IoT hub. |
170
+
|**Name**| Provide a name for your the logic app. |
171
+
|**Region**| Select a location close to you. |
172
+
|**Plan type**| Select **Consumption**, which is sufficient for this tutorial. |
158
173
159
-
**Location**: Use the same location that your IoT hub uses.
174
+
:::image type="content" source="media/iot-hub-monitoring-notifications-with-azure-logic-apps/create-a-logic-app.png" alt-text="Screenshot that shows creating a logic app in the Azure portal.":::
160
175
161
-

176
+
1. Select **Review + create**.
162
177
163
178
1. Select **Create**.
164
179
180
+
1. After the deployment completes, select **Go to resource** to open your logic app.
181
+
165
182
### Configure the logic app trigger
166
183
167
-
1.Open the logic app. The easiest way to get to the logic app is to select **Resource groups** from the resource pane, select your resource group, then select your logic app from the list of resources. When you select the logic app, the Logic Apps Designer opens.
184
+
1.On your logic app resource page in the Azure portal, open the **Logic app designer** from the **Development Tools** section of the resource menu.
168
185
169
-
1. In the Logic Apps Designer, scroll down to **Templates** and select **Blank Logic App**.
186
+
1. In the designer, scroll down to **Templates** and select **Blank Logic App**.
170
187
171
-

188
+
:::image type="content" source="media/iot-hub-monitoring-notifications-with-azure-logic-apps/designer-blank-logic-app.png" alt-text="Screenshot that shows selecting the Blank Logic App template.":::
172
189
173
-
1. Select the **All** tab and then select **Service Bus**.
190
+
1. Select the **All** tab to show all connectors and triggers, then select **Service Bus**.
174
191
175
-

192
+

176
193
177
194
1. Under **Triggers**, select **When one or more messages arrive in a queue (auto-complete)**.
178
195
179
-

196
+

180
197
181
198
1. Create a service bus connection.
182
-
1. Enter a connection name and select your Service Bus namespace from the list. The next screen opens.
183
199
184
-

200
+
1. Provide a **Connection name** and then paste the **Connection string** that you copied from your Service Bus namespace.
185
201
186
-
1. Select the service bus policy (RootManageSharedAccessKey). Then select **Create**.
202
+
1. Select **Create**.
187
203
188
-

204
+
1. On the next screen, use the drop-down menu to select the queue that you created in your Service Bus namespace. Then, enter `175` for **Maximum message count**.
189
205
190
-
1. On the final screen, for **Queue name**, select the queue that you created from the drop-down. Enter `175` for **Maximum message count**.
206
+
:::image type="content" source="media/iot-hub-monitoring-notifications-with-azure-logic-apps/designer-queue-settings.png" alt-text="Screenshot that shows configuring queue settings in the Logic app designer.":::
191
207
192
-

193
-
194
-
1. Select **Save** on the menu at the top of the Logic Apps Designer to save your changes.
208
+
1. Select **Save** on the logic app designer menu to save your changes.
195
209
196
210
### Configure the logic app action
197
211
212
+
1. Select **New step** in the logic app designer.
213
+
198
214
1. Create an SMTP service connection.
199
215
200
-
1.Select **New step**. In **Choose an action**, select the **All** tab.
216
+
1.Search for and select **SMTP**.
201
217
202
-
1. Type `smtp` in the search box, select the **SMTP** service in the search result, and then select **Send Email**.
218
+
:::image type="content" source="media/iot-hub-monitoring-notifications-with-azure-logic-apps/designer-smtp-connection.png" alt-text="Screenshot that shows selecting an SMTP connection in the logic app designer.":::
203
219
204
-

220
+
1. Select **Send Email (V3)** as the action for this step.
205
221
206
-
1.Enter the SMTP information for your mailbox, and then select **Create**.
222
+
1.Provide a **Connection name**, then fill out the rest of the fields with the SMTP information for the email account you want to use to send the notification messages.
207
223
208
-

224
+
Use the following links to find your SMTP information, depending on your mail provider:
209
225
210
-
Get the SMTP information for [Hotmail/Outlook.com](https://support.office.com/article/Add-your-Outlook-com-account-to-another-mail-app-73f3b178-0009-41ae-aab1-87b80fa94970), [Gmail](https://support.google.com/a/answer/176600?hl=en), and [Yahoo Mail](https://help.yahoo.com/kb/SLN4075.html).
> You may need to disable TLS/SSL to establish the connection. If this is the case and you want to re-enable TLS after the connection has been established, see the optional step at the end of this section.
214
232
215
-
1. From the **Add new parameter** drop-down on the **Send Email** step, select **From**, **To**, **Subject** and **Body**. Click or tap anywhere on the screen to close the selection box.
233
+
:::image type="content" source="media/iot-hub-monitoring-notifications-with-azure-logic-apps/designer-smtp-settings.png" alt-text="Screenshot that shows configuring the SMTP connection settings in the logic app designer.":::
1.Enter your email address for **From** and**To**, and `High temperature detected` for **Subject** and **Body**. If the **Add dynamic content from the apps and connectors used in this flow**dialog opens, select **Hide** to close it. You do not use dynamic content in this tutorial.
239
+
1. From the**Add new parameter** drop-down on the **Send Email**step, select the following parameters:
Click or tap anywhere on the screen to close the selection box.
247
+
248
+

249
+
250
+
1. Enter the following information for the email parameters you selected in the previous step:
251
+
252
+
| Parameter | Value |
253
+
| --------- | ----- |
254
+
|**From**| The email address that you configured for the SMTP connection. |
255
+
|**To**| The email address or addresses where you want to send notification emails. |
256
+
|**Subject**|`High temperature detected`. |
257
+
|**Body**|`High temperature detected`. |
258
+
259
+
If the **Add dynamic content** dialog opens, select **Hide** to close it. You do not use dynamic content in this tutorial.
260
+
261
+

262
+
263
+
1. Select **Save** to save the SMTP connection.
224
264
225
265
1. (Optional) If you had to disable TLS to establish a connection with your email provider and want to re-enable it, follow these steps:
226
266
@@ -232,21 +272,32 @@ In the preceding section, you set up your IoT hub to route messages containing a
232
272
233
273
1. On the **Edit API Connection** pane, select **Enable SSL?**, re-enter the password for your email account, and select **Save**.
234
274
235
-

275
+

236
276
237
277
Your logic app is now ready to process temperature alerts from the Service Bus queue and send notifications to your email account.
238
278
239
279
## Test the logic app
240
280
241
-
1.Start the client application on your device.
281
+
Start sending temperature messages from your IoT device to test the monitoring and notification pipeline.
242
282
243
-
1.If you're using a physical device, carefully bring a heat source near the heat sensor until the temperature exceeds 30 degrees C. If you're using the online simulator, the client code will randomly output telemetry messages that exceed 30 C.
283
+
1.Start the client application on your device. The client code randomly outputs telemetry messages, and sets the `temperatureAlert` property to `true` when the temperature exceeds 30 C.
244
284
245
285
1. You should begin receiving email notifications sent by the logic app.
246
286
247
287
> [!NOTE]
248
288
> Your email service provider may need to verify the sender identity to make sure it is you who sends the email.
249
289
290
+
## Clean up resources
291
+
292
+
If you don't need the resources that you created in this tutorial any longer, delete it and the resource group in the portal. To do so, select the **tutorial-iot-hub-rg** resource group that contains your IoT hub and select **Delete**.
293
+
294
+
Alternatively, use the CLI:
295
+
296
+
```azurecli-interactive
297
+
# Delete your resource group and its contents
298
+
az group delete --name tutorial-iot-hub-rg
299
+
```
300
+
250
301
## Next steps
251
302
252
303
You have successfully created a logic app that connects your IoT hub and your mailbox for temperature monitoring and notifications.
0 commit comments