Skip to content

Commit af39961

Browse files
committed
Added more log and troubleshooting info
1 parent 1f8017f commit af39961

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

articles/iot-hub/iot-hub-how-to-order-connection-state-events.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ From the moment your device runs, an order of operations activates:
2121
1. The Logic App processes the HTTP request with a condition you set (to track the connections and disconnections of your device)
2222
1. The Logic App tracks and stores the latest device connection state in Cosmos DB
2323

24+
<!--
2425
A sequence number is used in the *Device Connected* and *Device Disconnected* to track and order events.
2526
2627
The sequence number is a string representation of a hexadecimal number. You can use a string comparison to identify the larger number. If you're converting the string to hexadecimal, then the number will be a 256-bit number. The sequence number is strictly increasing, and the latest event will have a higher number than past events. This sequence is useful if you have frequent device connects and disconnects, and want to ensure only the latest event is used to trigger a downstream action, as Azure Event Grid doesn't support the ordering of events.
28+
-->
2729

2830
## Prerequisites
2931

@@ -111,6 +113,8 @@ Conditions help run specific actions after passing that specific condition. For
111113

112114
1. Select **+ New step**, then the **Built-in** tab, then find and select the control called **Condition**.
113115

116+
1. In your condition, change **And** to **Or**, since we want to capture either connection events or disconnection events in a single parse.
117+
114118
1. Select inside the **Choose a value** box and a pop up appears, showing the **Dynamic content** — the fields that can be selected.
115119

116120
* Choose **eventType**. The popup closes and you see **Body** is placed in **Select an output from previous steps**, automatically. Select **Condition** to reopen your conditional statement.
@@ -120,8 +124,6 @@ Conditions help run specific actions after passing that specific condition. For
120124
* This second row is similar to the first row, except we look for disconnection events.
121125

122126
Use **eventType**, **is equal to**, and **Microsoft.Devices.DeviceDisconnected** for the row values.
123-
124-
Add a checkmark in front of each row, as shown.
125127

126128
:::image type="content" source="media/iot-hub-how-to-order-connection-state-events/condition-detail.jpg" alt-text="Screenshot of the full For Each condition." lightbox="media/iot-hub-how-to-order-connection-state-events/condition-detail.jpg":::
127129

@@ -189,7 +191,12 @@ In this section, you configure your IoT Hub to publish events as they occur.
189191

190192
:::image type="content" source="media/iot-hub-how-to-order-connection-state-events/subscription-form.jpg" alt-text="Screenshot of the form to create an event subscription." lightbox="media/iot-hub-how-to-order-connection-state-events/subscription-form.jpg":::
191193

192-
Select **Create** to save the event subscription.
194+
Select **Create** to save the event subscription.
195+
196+
>[!IMPORTANT]
197+
> Wait a few minutes for your event to process before running your device. Anytime Azure services are created or changed, initiating the next step in your pipeline too soon could result in unnecessary errors. For example, if your IoT hub is not in an active state, it won't be ready to receive events. Check your IoT hub **Overview** page to see if your IoT hub is in an active state or not. If it's not, you'll see a warning at the top of the page.
198+
>
199+
> :::image type="content" source="media/iot-hub-how-to-order-connection-state-events/iot-hub-not-active.jpg" alt-text="Screenshot of an IoT Hub error that says it's not in an active state." lightbox="media/iot-hub-how-to-order-connection-state-events/iot-hub-not-active.jpg":::
193200
194201
## Run device and observe events
195202

@@ -205,11 +212,11 @@ Now that your event subscription is set up, let's test by connecting a device.
205212

206213
1. Select **Save**.
207214

208-
![Devices added to hub](./media/iot-hub-how-to-order-connection-state-events/add-iot-device.jpg)
215+
:::image type="content" source="media/iot-hub-how-to-order-connection-state-events/add-iot-device.jpg" alt-text="Screenshot of location of the Add Device button." lightbox="media/iot-hub-how-to-order-connection-state-events/add-iot-device.jpg":::
209216

210217
1. Click on the device again; now the connection strings and keys will be filled in. Copy and save the **Primary Connection String** for later use.
211218

212-
![ConnectionString for device](./media/iot-hub-how-to-order-connection-state-events/device-conn-string.jpg)
219+
:::image type="content" source="media/iot-hub-how-to-order-connection-state-events/device-conn-string.jpg" alt-text="Screenshot of location of the Primary Connection String for your device." lightbox="media/iot-hub-how-to-order-connection-state-events/device-conn-string.jpg":::
213220

214221
### Start Raspberry Pi simulator
215222

@@ -223,23 +230,28 @@ This sample app will trigger a device connected event.
223230

224231
1. In the coding area, replace the placeholder in Line 15 with your Azure IoT Hub device connection string that you saved at the end of the previous section.
225232

226-
![Paste in device connection string](./media/iot-hub-how-to-order-connection-state-events/raspconnstring.png)
233+
:::image type="content" source="media/iot-hub-how-to-order-connection-state-events/raspconnstring.png" alt-text="Screenshot of where to add your primary connection string in the Raspberry Pi script." lightbox="media/iot-hub-how-to-order-connection-state-events/raspconnstring.png":::
234+
235+
1. Run the application by selecting **Run**.
236+
237+
You see something similar to the following output that shows the sensor data and the messages that are sent to your IoT hub.
227238

228-
2. Run the application by selecting **Run**.
239+
:::image type="content" source="media/iot-hub-how-to-order-connection-state-events/raspmsg.png" alt-text="Screenshot of what to expect in your output console when you run the Raspberry Pi." lightbox="media/iot-hub-how-to-order-connection-state-events/raspmsg.png":::
229240

230-
You see something similar to the following output that shows the sensor data and the messages that are sent to your IoT hub.
241+
1. You can check your Logic App **Overview** page to check if your logic is being triggered. It'll say **Succeeded** or **Failed**. Checking here let's you know your logic app state if troubleshooting is needed. Expect a 15-30 second delay from when your trigger runs. If you need to troubleshoot your logic app, view this [Troubleshoot errors](/azure/logic-apps/logic-apps-diagnosing-failures?tabs=consumption) article.
231242

232-
![Running the application](./media/iot-hub-how-to-order-connection-state-events/raspmsg.png)
243+
:::image type="content" source="media/iot-hub-how-to-order-connection-state-events/logic-app-log.jpg" alt-text="Screenshot of the status updates on your logic app Overview page." lightbox="media/iot-hub-how-to-order-connection-state-events/logic-app-log.jpg":::
233244

234-
Select **Stop** to stop the simulator and trigger a **Device Disconnected** event.
245+
1. Select **Stop** to stop the simulator, which triggers a **Device Disconnected** event. This event will log on the Logic App **Overview** page, just as the connection event logged there.
235246

236-
You have now run a sample application to collect sensor data and send it to your IoT hub.
247+
You have now run a sample application to collect connection and disconnection events of your device, which go to your IoT hub.
237248

238249
### Observe events in Azure Cosmos DB
239250

240-
You can see results of the executed stored procedure in your Cosmos DB document. The query **SELECT * FROM d** shows the document. Each row contains the latest device connection state per device.
251+
You can see results of the executed logic app in your Cosmos DB document. The document appears in your **Items** collection when you refresh the page. Each row contains the latest device connection state per device.
241252

242253
![How to outcome](./media/iot-hub-how-to-order-connection-state-events/cosmosDB-outcome.png)
254+
:::image type="content" source="media/iot-hub-how-to-order-connection-state-events/logic-app-log.jpg" alt-text="Screenshot of the status updates on your logic app Overview page." lightbox="media/iot-hub-how-to-order-connection-state-events/logic-app-log.jpg":::
243255

244256
## Use the Azure CLI
245257

0 Bytes
Loading
21.5 KB
Loading
26.4 KB
Loading

0 commit comments

Comments
 (0)