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
+41-27Lines changed: 41 additions & 27 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: 07/18/2019
10
+
ms.date: 02/02/2024
11
11
---
12
12
13
13
# Tutorial: Monitor IoT devices and send notifications with Azure Logic Apps
@@ -25,7 +25,7 @@ In this tutorial, you perform the following tasks:
25
25
> Create a route in your IoT hub that sends messages to the Service Bus queue if the messages contain anomalous temperature readings.
26
26
> Create a logic app that watches for messaging arriving in the queue and sends an email alert.
27
27
28
-
The client code running on your device sets an application property, `temperatureAlert`, on every telemetry message it sends to your IoT hub. When the client code detects a temperature above 30 C, it sets this property to `true`; otherwise, it sets the property to `false`.
28
+
The client code running on your device sets an application property, `temperatureAlert`, on every telemetry message it sends to your IoT hub. When the client code detects a temperature above a given threshold, it sets this property to `true`; otherwise, it sets the property to `false`.
29
29
30
30
Messages arriving at your IoT hub look similar to the following, with the telemetry data contained in the body and the `temperatureAlert` property contained in the application properties (system properties aren't shown):
31
31
@@ -47,53 +47,67 @@ If you don't have an Azure subscription, [create a free account](https://azure.m
47
47
48
48
## Prerequisites
49
49
50
-
Before you begin this tutorial, complete one of the [Send telemetry](../iot-develop/quickstart-send-telemetry-iot-hub.md) quickstarts in the development language of your choice. Alternatively, you can use any device app that sends temperature telemetry; for example, the [Raspberry Pi online simulator](iot-hub-raspberry-pi-web-simulator-get-started.md). These articles cover the following requirements:
50
+
Prepare the following prerequisites before beginning this tutorial.
51
51
52
52
* An active Azure subscription.
53
-
* An Azure IoT hub in your subscription.
54
-
* A client app that sends temperature data to your Azure IoT hub.
53
+
* An IoT hub in your subscription.
54
+
* A client app that sends temperature data to your Azure IoT hub. This tutorial filters device-to-cloud messages based on a message property called `temperatureAlert`. Some samples that generate messages with this property include:
* C SDK: [iothub_II_client_shared_sample](https://github.com/Azure/azure-iot-sdk-c/blob/main/iothub_client/samples/iothub_ll_client_shared_sample/iothub_ll_client_shared_sample.c)
60
+
* Codeless: [Raspberry Pi online simulator](iot-hub-raspberry-pi-web-simulator-get-started.md)
55
61
56
62
## Create Service Bus namespace and queue
57
63
58
-
Create a Service Bus namespace and queue. Later in this article, you create a routing rule in your IoT hub to direct messages that contain a temperature alert to the Service Bus queue, where they're picked up by a logic app and trigger it to send a notification email.
64
+
Create a Service Bus namespace and queue. Later in this article, you create a routing rule in your IoT hub to direct messages that contain a temperature alert to the Service Bus queue. A logic app monitors the queue for incoming messages and sends a notification for each alert.
59
65
60
66
### Create a Service Bus namespace
61
67
62
-
1. On the [Azure portal](https://portal.azure.com/), select **+ Create a resource** > **Integration** > **Service Bus**.
68
+
1. On the [Azure portal](https://portal.azure.com/), use the search bar to search for and select **Service Bus**.
69
+
70
+
1. Select **Create** to create a service bus namespace.
63
71
64
72
1. On the **Create namespace** pane, provide the following information:
65
73
66
-
**Name**: The name of the service bus namespace. The namespace must be unique across Azure.
74
+
| Parameter | Value |
75
+
| --------- | ----- |
76
+
|**Subscription**| Choose the same subscription that contains your IoT hub. |
77
+
|**Resource group**| Choose the same resource group that contains your IoT hub. |
78
+
|**Namespace name**| Provide a name for your service bus namespace. The namespace must be unique across Azure. |
79
+
|**Location**| Choose the same location that your IoT hub uses. |
80
+
|**Pricing tier**| Select **Basic** from the drop-down list. The Basic tier is sufficient for this tutorial. |
67
81
68
-
**Pricing tier**: Select **Basic** from the drop-down list. The Basic tier is sufficient for this tutorial.
82
+
1. Select **Review + create**.
69
83
70
-
**Resource group**: Use the same resource group that your IoT hub uses.
84
+
1. Select **Create**.
71
85
72
-
**Location**: Use the same location that your IoT hub uses.
86
+
1. Wait for the deployment to complete, then select **Go to resource**.
73
87
74
-

88
+
### Add a Service Bus queue to the namespace
75
89
76
-
1.Select **Create**. Wait for the deployment to complete before moving on to the next step.
90
+
1.On the **Overview** page of your Service Bus namespace, select **Queue**.
77
91
78
-
### Add a Service Bus queue to the namespace
92
+
:::image type="content" source="./media/iot-hub-monitoring-notifications-with-azure-logic-apps/namespace-add-queue.png" alt-text="Screenshot of the namespace overview page to add a queue.":::
79
93
80
-
1.Open the Service Bus namespace. The easiest way to get to the Service Bus namespace is to select **Resource groups**from the resource pane, select your resource group, then select the Service Bus namespace from the list of resources.
94
+
1.In the **Name**field, provide a name for the queue. Accept the default values for the other fields and select **Create**.
81
95
82
-
1.On the **Service Bus Namespace** pane, select **+ Queue**.
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
83
97
84
-
1. Enter a name for the queue and then select **Create**. When the queue has been successfully created, the **Create queue** pane closes.
98
+
:::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.":::
85
99
86
-

100
+
1. On the **Service Bus Queue** pane, select **Shared access policies** from the **Settings** section of the resource menu. Then, select **Add** to add a policy.
87
101
88
-
1. Back on the **Service Bus Namespace** pane, under **Entities**, select **Queues**. Open the Service Bus queue from the list, and then select **Shared access policies** > **+ Add**.
102
+
:::image type="content" source="./media/iot-hub-monitoring-notifications-with-azure-logic-apps/queue-shared-access-policies-add.png" alt-text="Screenshot that shows adding a shared access policy to a Service Bus queue.":::
89
103
90
-
1.Enter a name for the policy, check**Manage**, and then select **Create**.
104
+
1.In the **Policy name** field, provide a name for the policy. Check**Manage**, and then select **Create**.
91
105
92
-

106
+
:::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.":::
93
107
94
108
## Add a custom endpoint and routing rule to your IoT hub
95
109
96
-
Add a custom endpoint for the Service Bus queue to your IoT hub and 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).
110
+
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).
97
111
98
112
### Add a custom endpoint and route
99
113
@@ -108,11 +122,11 @@ Add a custom endpoint for the Service Bus queue to your IoT hub and create a mes
108
122
| Parameter | Value |
109
123
| --------- | ----- |
110
124
|**Endpoint type**| Select **Service Bus queue**. |
111
-
|**Endpoint name**| Provide a unique name for a new endpoint, or select **Select existing**to choose an existing Service Bus queue endpoint. |
112
-
|**Service Bus namespace**| Use the drop-down menu to select an existing Service Bus namespace in your subscription. |
113
-
|**Service Bus queue**| Use the drop-down menu to select an existing queue in your namespace. |
125
+
|**Endpoint name**| Provide a name for the new endpoint that maps to your Service Bus queue. |
126
+
|**Service Bus namespace**| Use the drop-down menu to select the Service Bus namespace that you created in the previous section. |
127
+
|**Service Bus queue**| Use the drop-down menu to select the Service Bus queue that you created in your namespace. |
114
128
115
-
:::image type="content" source="media/iot-hub-monitoring-notifications-with-azure-logic-apps/3-add-iot-hub-endpoint-azure-portal.png" alt-text="Screenshot that shows the Add a service bus queue endpoint pane.":::
129
+
:::image type="content" source="media/iot-hub-monitoring-notifications-with-azure-logic-apps/add-a-route-endpoint.png" alt-text="Screenshot that shows how to create a service bus queue endpoint for your route.":::
116
130
117
131
1. Select **Create + next**.
118
132
@@ -124,7 +138,7 @@ Add a custom endpoint for the Service Bus queue to your IoT hub and create a mes
124
138
|**Data source**| Keep the default **Device Telemetry Message** data source. |
125
139
|**Routing query**| Enter `temperatureAlert = "true"` as the query string. |
126
140
127
-
:::image type="content" source="media/iot-hub-monitoring-notifications-with-azure-logic-apps/4-add-routing-rule-azure-portal.png" alt-text="Screenshot that shows adding a route with a query.":::
141
+
:::image type="content" source="media/iot-hub-monitoring-notifications-with-azure-logic-apps/add-a-route-route.png" alt-text="Screenshot that shows adding a route with a query.":::
0 commit comments