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/event-grid/publish-iot-hub-events-to-logic-apps.md
+23-16Lines changed: 23 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ ms.custom: devx-track-azurecli
14
14
15
15
Azure Event Grid enables you to react to events in IoT Hub by triggering actions in your downstream business applications.
16
16
17
-
This article walks through a sample configuration that uses IoT Hub and Event Grid. At the end, you have an Azure logic app set up to send a notification email every time a device connects or disconnects to your IoT hub. Event Grid can be used to get timely notification about critical devices disconnecting. Metrics and Diagnostics can take several (i.e. 20 or more -- though we don't want to put a number on it) minutes to show up in logs/alerts. That might be unacceptable for critical infrastructure.
17
+
This article walks through a sample configuration that uses IoT Hub and Event Grid. At the end, you have an Azure logic app set up to send a notification email every time a device connects or disconnects to your IoT hub. Event Grid can be used to get timely notification about critical devices disconnecting. Metrics and Diagnostics can take several minutes (such as 20 minutes or more) to show up in logs / alerts. Longer processing times might be unacceptable for critical infrastructure.
:::image type="content" source="./media/publish-iot-hub-events-to-logic-apps/portal-cloud-shell.png" alt-text="Screenshot of how to open the Azure Cloud Shell from the Azure portal." lightbox="./media/publish-iot-hub-events-to-logic-apps/portal-cloud-shell.png":::
36
36
37
37
1. Run the following command to create a new resource group:
38
38
@@ -46,11 +46,11 @@ You can quickly create a new IoT hub using the Azure Cloud Shell terminal in the
46
46
az iot hub create --name {your iot hub name} --resource-group {your resource group name} --sku S1
47
47
```
48
48
49
-
1. Minimize the Cloud Shell terminal. You will return to the shell later in the tutorial.
49
+
1. Minimize the Cloud Shell terminal. You'll return to the shell later in the tutorial.
50
50
51
51
## Create a logic app
52
52
53
-
Next, create a logic app and add an HTTP event grid trigger that processes requests from IoT hub.
53
+
Next, create a logic app and add an HTTP Event Grid trigger that processes requests from IoT hub.
54
54
55
55
### Create a logic app resource
56
56
@@ -112,6 +112,9 @@ A trigger is a specific event that starts your logic app. For this tutorial, the
112
112
"metadataVersion": "1"
113
113
}]
114
114
```
115
+
116
+
> [!IMPORTANT]
117
+
> Be sure to paste the JSON snippet into the box provided by the **Use sample payload to generate schema** link and not directly into the **Request Body JSON Schema** box. The sample payload link provides a way to generate the JSON content based on the JSON snippet. The final JSON that ends up in the request body is different than the JSON snippet.
115
118
116
119
This event publishes when a device is connected to an IoT hub.
117
120
@@ -122,11 +125,11 @@ A trigger is a specific event that starts your logic app. For this tutorial, the
122
125
123
126
Actions are any steps that occur after the trigger starts the logic app workflow. For this tutorial, the action is to send an email notification from your email provider.
124
127
125
-
1. Select **New step**. This opens a window to **Choose an action**.
128
+
1. Select **New step**. A window appears, prompting you to **Choose an action**.
126
129
127
130
1. Search for **Outlook**.
128
131
129
-
1. Based on your email provider, find and select the matching connector. This tutorial uses **Outlook.com**. The steps for other email providers are similar.
132
+
1. Based on your email provider, find and select the matching connector. This tutorial uses **Outlook.com**. The steps for other email providers are similar. Alternatively, use Office 365 Outlook to skip the sign-in step.
@@ -138,7 +141,11 @@ Actions are any steps that occur after the trigger starts the logic app workflow
138
141
139
142
***To**: Enter the email address to receive the notification emails. For this tutorial, use an email account that you can access for testing.
140
143
141
-
***Subject**: Fill in the text for the subject. When you click on the Subject text box, you can select dynamic content to include. For example, this tutorial uses `IoT Hub alert: {eventType}`. If you can't see Dynamic content, select the **Add dynamic content** hyperlink -- this toggles it on and off.
144
+
***Subject**: Fill in the text for the subject. When you click on the Subject text box, you can select dynamic content to include. For example, this tutorial uses `IoT Hub alert: {eventType}`. If you can't see **Dynamic content**, select the **Add dynamic content** hyperlink to toggle the **Dynamic content** view on or off.
145
+
146
+
After selecting `eventType`, you'll see the email form output so far. Select the **Send and email (V2)** to edit the body of your email.
147
+
148
+
:::image type="content" source="./media/publish-iot-hub-events-to-logic-apps/send-email.png" alt-text="Screenshot of the condensed body output form." lightbox="./media/publish-iot-hub-events-to-logic-apps/send-email.png":::
142
149
143
150
***Body**: Write the text for your email. Select JSON properties from the selector tool to include dynamic content based on event data. If you can't see the Dynamic content, select the **Add dynamic content** hyperlink under the **Body** text box. If it doesn't show you the fields you want, click *more* in the Dynamic content screen to include the fields from the previous action.
144
151
@@ -150,7 +157,7 @@ Actions are any steps that occur after the trigger starts the logic app workflow
150
157
151
158
### Copy the HTTP URL
152
159
153
-
Before you leave the Logic Apps Designer, copy the URL that your logic apps is listening to for a trigger. You use this URL to configure Event Grid.
160
+
Before you leave the Logic Apps Designer, copy the URL that your logic app is listening to for a trigger. You use this URL to configure Event Grid.
154
161
155
162
1. Expand the **When a HTTP request is received** trigger configuration box by clicking on it.
156
163
@@ -164,7 +171,7 @@ Before you leave the Logic Apps Designer, copy the URL that your logic apps is l
164
171
165
172
In this section, you configure your IoT Hub to publish events as they occur.
166
173
167
-
1. In the Azure portal, navigate to your IoT hub. You can do this by selecting **Resource groups**, then select the resource group for this tutorial, and then select your IoT hub from the list of resources.
174
+
1. In the Azure portal, navigate to your IoT hub. You can find your IoT hub by selecting **IoT Hub** from your Azure dashboard, then select your IoT hub instance from the list of resources.
168
175
169
176
1. Select **Events**.
170
177
@@ -205,27 +212,27 @@ In this section, you configure your IoT Hub to publish events as they occur.
205
212
206
213
Test your logic app by quickly simulating a device connection using the Azure CLI.
207
214
208
-
1. Select the Cloud Shell button to re-open your terminal.
215
+
1. Select the Cloud Shell button to reopen your terminal.
209
216
210
217
1. Run the following command to create a simulated device identity:
211
218
212
219
```azurecli
213
220
az iot hub device-identity create --device-id simDevice --hub-name {YourIoTHubName}
214
221
```
215
222
216
-
This could take a minute. You'll see a `json` printout once it's created.
223
+
The processing could take a minute. You'll see a JSON printout in your console once it's created.
217
224
218
225
1. Run the following command to simulate connecting your device to IoT Hub and sending telemetry:
219
226
220
227
```azurecli
221
228
az iot device simulate -d simDevice -n {YourIoTHubName}
222
229
```
223
230
224
-
1. When the simulated device connects to IoT Hub, you will receive an email notifying you of a "DeviceConnected" event.
231
+
1. When the simulated device connects to IoT Hub, you'll receive an email notifying you of a "DeviceConnected" event.
225
232
226
-
1. When the simulation completes, you will receive an email notifying you of a "DeviceDisconnected" event.
233
+
1. When the simulation completes, you'll receive an email notifying you of a "DeviceDisconnected" event.
:::image type="content" source="./media/publish-iot-hub-events-to-logic-apps/alert-mail.png" alt-text="Screenshot of the email you should receive." lightbox="./media/publish-iot-hub-events-to-logic-apps/alert-mail.png":::
229
236
230
237
## Clean up resources
231
238
@@ -235,7 +242,7 @@ To delete all of the resources created in this tutorial, delete the resource gro
235
242
236
243
1. Select **Resource groups**, then select the resource group you created for this tutorial.
237
244
238
-
2. On the Resource group pane, select **Delete resource group**. You are prompted to enter the resource group name, and then you can delete it. All of the resources contained therein are also removed.
245
+
2. On the Resource group pane, select **Delete resource group**. You're prompted to enter the resource group name, and then you can delete it. All of the resources contained therein are also removed.
239
246
240
247
## Next steps
241
248
@@ -246,4 +253,4 @@ To delete all of the resources created in this tutorial, delete the resource gro
246
253
For a complete list of supported Logic App connectors, see the
0 commit comments