Skip to content

Commit 393a5b0

Browse files
authored
Merge pull request #44536 from ash2017/IoTHubEGGA_June2018
adding new event in EG
2 parents c1345b6 + fdc5ef7 commit 393a5b0

37 files changed

+494
-96
lines changed

articles/event-grid/event-schema-iot-hub.md

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,34 @@ Azure IoT Hub emits the following event types:
2727
| ---------- | ----------- |
2828
| Microsoft.Devices.DeviceCreated | Published when a device is registered to an IoT hub. |
2929
| Microsoft.Devices.DeviceDeleted | Published when a device is deleted from an IoT hub. |
30+
| Microsoft.Devices.DeviceConnected | Published when a device is connected to an IoT hub. |
31+
| Microsoft.Devices.DeviceDisconnected | Published when a device is disconnected from an IoT hub. |
3032

3133
## Example event
3234

35+
The schema for DeviceConnected and DeviceDisconnected events have the same structure. This sample event shows the schema of an event raised when a device is connected to an IoT hub:
36+
37+
```json
38+
[{
39+
"id": "f6bbf8f4-d365-520d-a878-17bf7238abd8",
40+
"topic": "/SUBSCRIPTIONS/<subscription ID>/RESOURCEGROUPS/<resource group name>/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/<hub name>",
41+
"subject": "devices/LogicAppTestDevice",
42+
"eventType": "Microsoft.Devices.DeviceConnected",
43+
"eventTime": "2018-06-02T19:17:44.4383997Z",
44+
"data": {
45+
"deviceConnectionStateEventInfo": {
46+
"sequenceNumber":
47+
"000000000000000001D4132452F67CE200000002000000000000000000000001"
48+
},
49+
"hubName": "egtesthub1",
50+
"deviceId": "LogicAppTestDevice",
51+
"moduleId" : "DeviceModuleID"
52+
},
53+
"dataVersion": "1",
54+
"metadataVersion": "1"
55+
}]
56+
```
57+
3358
The schema for DeviceCreated and DeviceDeleted events have the same structure. This sample event shows the schema of an event raised when a device is registered to an IoT hub:
3459

3560
```json
@@ -43,6 +68,7 @@ The schema for DeviceCreated and DeviceDeleted events have the same structure. T
4368
"twin": {
4469
"deviceId": "LogicAppTestDevice",
4570
"etag": "AAAAAAAAAAE=",
71+
"deviceEtag": "null",
4672
"status": "enabled",
4773
"statusUpdateTime": "0001-01-01T00:00:00",
4874
"connectionState": "Disconnected",
@@ -70,11 +96,9 @@ The schema for DeviceCreated and DeviceDeleted events have the same structure. T
7096
}
7197
},
7298
"hubName": "egtesthub1",
73-
"deviceId": "LogicAppTestDevice",
74-
"operationTimestamp": "2018-01-02T19:17:44.4383997Z",
75-
"opType": "DeviceCreated"
99+
"deviceId": "LogicAppTestDevice"
76100
},
77-
"dataVersion": "",
101+
"dataVersion": "1",
78102
"metadataVersion": "1"
79103
}]
80104
```
@@ -94,17 +118,29 @@ All events contain the same top-level data:
94118
| dataVersion | string | The schema version of the data object. The publisher defines the schema version. |
95119
| metadataVersion | string | The schema version of the event metadata. Event Grid defines the schema of the top-level properties. Event Grid provides this value. |
96120

97-
The contents of the data object are different for each event publisher. For IoT Hub events, the data object contains the following properties:
121+
For all IoT Hub events, the data object contains the following properties:
98122

99123
| Property | Type | Description |
100124
| -------- | ---- | ----------- |
101125
| hubName | string | Name of the IoT Hub where the device was created or deleted. |
102126
| deviceId | string | The unique identifier of the device. This case-sensitive string can be up to 128 characters long, and supports ASCII 7-bit alphanumeric characters plus the following special characters: `- : . + % _ # * ? ! ( ) , = @ ; $ '`. |
103-
| operationTimestamp | string | The ISO8601 timestamp of the operation. |
104-
| opType | string | The event type specified for this operation by the IoT Hub: either `DeviceCreated` or `DeviceDeleted`.
127+
128+
The contents of the data object are different for each event publisher. For **Device Connected** and **Device Disconnected** IoT Hub events, the data object contains the following properties:
129+
130+
| Property | Type | Description |
131+
| -------- | ---- | ----------- |
132+
| moduleId | string | The unique identifier of the module. This field is output only for module devices. This case-sensitive string can be up to 128 characters long, and supports ASCII 7-bit alphanumeric characters plus the following special characters: `- : . + % _ # * ? ! ( ) , = @ ; $ '`. |
133+
| deviceConnectionStateEventInfo | object | Device connection state event information
134+
| sequenceNumber | string | A number which helps indicate order of device connected or device disconnected events. Latest event will have a sequence number that is higher than the previous event. This number may change by more than 1, but is strictly increasing. See [how to use sequence number](../iot-hub/iot-hub-how-to-order-connection-state-events.md). |
135+
136+
The contents of the data object are different for each event publisher. For **Device Created** and **Device Deleted** IoT Hub events, the data object contains the following properties:
137+
138+
| Property | Type | Description |
139+
| -------- | ---- | ----------- |
105140
| twin | object | Information about the device twin, which is the cloud represenation of application device metadata. |
106141
| deviceID | string | The unique identifier of the device twin. |
107-
| etag | string | A piece of information that describes the content of the device twin. Each etag is guaranteed to be unique per device twin. |
142+
| etag | string | A validator for ensuring consistency of updates to a device twin. Each etag is guaranteed to be unique per device twin. |
143+
| deviceEtag| string | A validator for ensuring consistency of updates to a device registry. Each deviceEtag is guaranteed to be unique per device registry. |
108144
| status | string | Whether the device twin is enabled or disabled. |
109145
| statusUpdateTime | string | The ISO8601 timestamp of the last device twin status update. |
110146
| connectionState | string | Whether the device is connected or disconnected. |

articles/event-grid/event-sources.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ For examples of Event Hubs as a handler, see [Event Hubs handler](event-handlers
7070

7171
## IoT Hub
7272

73-
Subscribe to IoT Hub events to respond to device created and deleted events.
73+
Subscribe to IoT Hub events to respond to device created, deleted, connected and disconnected events.
7474

7575
|Title |Description |
7676
|---------|---------|
77-
| [Tutorial: send email notifications about Azure IoT Hub events using Logic Apps](publish-iot-hub-events-to-logic-apps.md) | A logic app sends a notification email every time a device is added to your IoT hub. |
78-
| [Overview: react to IoT Hub events by using Event Grid to trigger actions](../iot-hub/iot-hub-event-grid.md) | Overview of integrating Iot Hubs with Event Grid. |
77+
| [Send email notifications about Azure IoT Hub events using Logic Apps](publish-iot-hub-events-to-logic-apps.md) | A logic app sends a notification email every time a device is added to your IoT Hub. |
78+
| [React to IoT Hub events by using Event Grid to trigger actions](../iot-hub/iot-hub-event-grid.md) | Overview of integrating IoT Hub with Event Grid. |
7979
| [Event schema](event-schema-iot-hub.md) | Shows fields in IoT Hub events. |
80+
| [Order device connected and device disconnected events](../iot-hub/iot-hub-how-to-order-connection-state-events.md) | Shows how to order device connection state events. |
8081

8182
## Media Services
8283

21 KB
Loading
48.3 KB
Loading
55.5 KB
Loading

articles/event-grid/publish-iot-hub-events-to-logic-apps.md

Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ This article walks through a sample configuration that uses IoT Hub and Event gr
2525

2626
* An email account from any email provider that is supported by Azure Logic Apps, like Office 365 Outlook, Outlook.com, or Gmail. This email account is used to send the event notifications. For a complete list of supported Logic App connectors, see the [Connectors overview](https://docs.microsoft.com/connectors/)
2727
* An active Azure account. If you don't have one, you can [create a free account](http://azure.microsoft.com/pricing/free-trial/).
28-
* An Iot hub in Azure. If you haven't created one yet, see [Get started with IoT Hub](../iot-hub/iot-hub-csharp-csharp-getstarted.md) for a walkthrough.
28+
* An IoT Hub in Azure. If you haven't created one yet, see [Get started with IoT Hub](../iot-hub/iot-hub-csharp-csharp-getstarted.md) for a walkthrough.
2929

3030
## Create a logic app
3131

3232
First, create a logic app and add an Event grid trigger that monitors the resource group for your virtual machine.
3333

3434
### Create a logic app resource
3535

36-
37-
1. In the [Azure portal](https://portal.azure.com), select **New** > **Enterprise Integration** > **Logic App**.
36+
1. In the [Azure portal](https://portal.azure.com), select **New** > **Integration** > **Logic App**.
3837

3938
![Create logic app](./media/publish-iot-hub-events-to-logic-apps/select-logic-app.png)
4039

@@ -50,12 +49,12 @@ First, create a logic app and add an Event grid trigger that monitors the resour
5049
5150
4. In the Logic App Designer under **Templates**, choose **Blank Logic App** so that you can build your logic app from scratch.
5251

53-
## Select a trigger
52+
### Select a trigger
5453

5554
A trigger is a specific event that starts your logic app. For this tutorial, the trigger that sets off the workflow is receiving a request over HTTP.
5655

5756
1. In the connectors and triggers search bar, type **HTTP**.
58-
2. Select **Request - When a HTTP request is received** as the trigger.
57+
2. Select **Request - When an HTTP request is received** as the trigger.
5958

6059
![Select HTTP request trigger](./media/publish-iot-hub-events-to-logic-apps/http-request-trigger.png)
6160

@@ -65,64 +64,60 @@ A trigger is a specific event that starts your logic app. For this tutorial, the
6564

6665
4. Paste the following sample JSON code into the text box, then select **Done**:
6766

68-
```json
69-
[{
70-
"id": "56afc886-767b-d359-d59e-0da7877166b2",
71-
"topic": "/SUBSCRIPTIONS/<Subscription ID>/RESOURCEGROUPS/<Resource group name>/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/<IoT hub name>",
72-
"subject": "devices/LogicAppTestDevice",
73-
"eventType": "Microsoft.Devices.DeviceCreated",
74-
"eventTime": "2018-01-02T19:17:44.4383997Z",
75-
"data": {
76-
"twin": {
77-
"deviceId": "LogicAppTestDevice",
78-
"etag": "AAAAAAAAAAE=",
79-
"status": "enabled",
80-
"statusUpdateTime": "0001-01-01T00:00:00",
81-
"connectionState": "Disconnected",
82-
"lastActivityTime": "0001-01-01T00:00:00",
83-
"cloudToDeviceMessageCount": 0,
84-
"authenticationType": "sas",
85-
"x509Thumbprint": {
86-
"primaryThumbprint": null,
87-
"secondaryThumbprint": null
88-
},
89-
"version": 2,
90-
"properties": {
91-
"desired": {
92-
"$metadata": {
93-
"$lastUpdated": "2018-01-02T19:17:44.4383997Z"
94-
},
95-
"$version": 1
96-
},
97-
"reported": {
98-
"$metadata": {
99-
"$lastUpdated": "2018-01-02T19:17:44.4383997Z"
100-
},
101-
"$version": 1
102-
}
103-
}
104-
},
105-
"hubName": "egtesthub1",
106-
"deviceId": "LogicAppTestDevice",
107-
"operationTimestamp": "2018-01-02T19:17:44.4383997Z",
108-
"opType": "DeviceCreated"
109-
},
110-
"dataVersion": "",
111-
"metadataVersion": "1"
112-
}]
113-
```
114-
5. You may receive a pop-up notification that says, **Remember to include a Content-Type header set to application/json in your request.** You can safely ignore this suggestion, and move on to the next section.
67+
```json
68+
[{
69+
"id": "56afc886-767b-d359-d59e-0da7877166b2",
70+
"topic": "/SUBSCRIPTIONS/<subscription ID>/RESOURCEGROUPS/<resource group name>/PROVIDERS/MICROSOFT.DEVICES/IOTHUBS/<hub name>",
71+
"subject": "devices/LogicAppTestDevice",
72+
"eventType": "Microsoft.Devices.DeviceCreated",
73+
"eventTime": "2018-01-02T19:17:44.4383997Z",
74+
"data": {
75+
"twin": {
76+
"deviceId": "LogicAppTestDevice",
77+
"etag": "AAAAAAAAAAE=",
78+
"deviceEtag": "null",
79+
"status": "enabled",
80+
"statusUpdateTime": "0001-01-01T00:00:00",
81+
"connectionState": "Disconnected",
82+
"lastActivityTime": "0001-01-01T00:00:00",
83+
"cloudToDeviceMessageCount": 0,
84+
"authenticationType": "sas",
85+
"x509Thumbprint": {
86+
"primaryThumbprint": null,
87+
"secondaryThumbprint": null
88+
},
89+
"version": 2,
90+
"properties": {
91+
"desired": {
92+
"$metadata": {
93+
"$lastUpdated": "2018-01-02T19:17:44.4383997Z"
94+
},
95+
"$version": 1
96+
},
97+
"reported": {
98+
"$metadata": {
99+
"$lastUpdated": "2018-01-02T19:17:44.4383997Z"
100+
},
101+
"$version": 1
102+
}
103+
}
104+
},
105+
"hubName": "egtesthub1",
106+
"deviceId": "LogicAppTestDevice"
107+
},
108+
"dataVersion": "1",
109+
"metadataVersion": "1"
110+
}]
111+
```
115112

113+
5. You may receive a pop-up notification that says, **Remember to include a Content-Type header set to application/json in your request.** You can safely ignore this suggestion, and move on to the next section.
116114

117115
### Create an action
118116

119117
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.
120118

121-
1. Select **New step** then **Add an action**.
122-
123-
![New step, add an action](./media/publish-iot-hub-events-to-logic-apps/new-step.png)
124-
125-
2. Search for **Email**.
119+
1. Select **New step**. This will open a window to **Choose an action**.
120+
2. Search for **Email**.
126121
3. Based on your email provider, find and select the matching connector. This tutorial uses **Office 365 Outlook**. The steps for other email providers are similar.
127122

128123
![Select email provider connector](./media/publish-iot-hub-events-to-logic-apps/o365-outlook.png)
@@ -150,7 +145,7 @@ Before you leave the Logic Apps Designer, copy the URL that your logic apps is l
150145

151146
3. Save this URL so that you can refer to it in the next section.
152147

153-
## Publish an event from IoT Hub
148+
## Configure subscription for IoT Hub events
154149

155150
In this section, you configure your IoT Hub to publish events as they occur.
156151

@@ -164,21 +159,22 @@ In this section, you configure your IoT Hub to publish events as they occur.
164159
![Create new event subscription](./media/publish-iot-hub-events-to-logic-apps/event-subscription.png)
165160

166161
4. Create the event subscription with the following values:
167-
* **Name**: Provide a descriptive name.
168-
* **Subscribe to all event types**: Unselect the checkbox.
169-
* **Event types**: Select **DeviceCreated**.
170-
* **Subscriber type**: Select **Web Hook**.
171-
* **Subscriber endpoint**: Paste the URL that you copied from your logic app.
162+
* **Event Type**: Uncheck Subscribe to all event types and select **Device Created** from the menu.
163+
* **Endpoint Details**: Select Endpoint Type as **Web Hook** and click on select endpoint and paste the URL that you copied from your logic app and confirm selection.
164+
165+
![select endpoint url](./media/publish-iot-hub-events-to-logic-apps/endpoint-url.png)
172166

173-
You could save the event subscription here, and receive notifications for every device that is created in your IoT hub. For this tutorial, though, let's use the optional fields to filter for specific devices:
167+
* **Event Subscription Details**: Provide a descriptive name and select **Event Grid Schema**
174168

175-
* **Prefix filter**: Enter `devices/Building1_` to filter for device events in building 1.
176-
* **Suffix filter**: Enter `_Temperature` to filter for device events related to temperature.
169+
You could save the event subscription here, and receive notifications for every device that is created in your IoT hub. For this tutorial, though, let's use the optional fields to filter for specific devices:
177170

178-
When you're done, the form should look like the following example:
171+
* **Subject Begins With**: Enter `devices/Building1_` to filter for device events in building 1.
172+
* **Subject Ends With**: Enter `_Temperature` to filter for device events related to temperature.
179173

180-
![Sample event subscription form](./media/publish-iot-hub-events-to-logic-apps/subscription-form.png)
174+
When you're done, the form should look like the following example:
181175

176+
![Sample event subscription form](./media/publish-iot-hub-events-to-logic-apps/subscription-form.png)
177+
182178
5. Select **Create** to save the event subscription.
183179

184180
## Create a new device
@@ -223,8 +219,8 @@ Even if you keep your IoT hub, you may want to delete the event subscription tha
223219

224220
## Next steps
225221

226-
Learn more about [Reacting to IoT Hub events by using Event Grid to trigger actions](../iot-hub/iot-hub-event-grid.md).
227-
228-
Learn about what else you can do with [Event Grid](overview.md).
222+
* Learn more about [Reacting to IoT Hub events by using Event Grid to trigger actions](../iot-hub/iot-hub-event-grid.md).
223+
* [Learn how to order device connected and disconnected events](../iot-hub/iot-hub-how-to-order-connection-state-events.md)
224+
* Learn about what else you can do with [Event Grid](overview.md).
229225

230226

articles/iot-hub/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@
148148
href: iot-hub-reliability-features-in-sdks.md
149149
- name: Query Avro data from a hub route
150150
href: iot-hub-query-avro-data.md
151+
- name: Order device connection state events from Event Grid
152+
href: iot-hub-how-to-order-connection-state-events.md
151153
- name: Send cloud-to-device messages
152154
items:
153155
- name: .NET

articles/iot-hub/iot-hub-devguide-identity-registry.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ The device data that a given IoT solution stores depends on the specific require
8383
The IoT Hub identity registry contains a field called **connectionState**. Only use the **connectionState** field during development and debugging. IoT solutions should not query the field at run time. For example, do not query the **connectionState** field to check if a device is connected before you send a cloud-to-device message or an SMS.
8484

8585
If your IoT solution needs to know if a device is connected, you should implement the *heartbeat pattern*.
86-
8786
In the heartbeat pattern, the device sends device-to-cloud messages at least once every fixed amount of time (for example, at least once every hour). Therefore, even if a device does not have any data to send, it still sends an empty device-to-cloud message (usually with a property that identifies it as a heartbeat). On the service side, the solution maintains a map with the last heartbeat received for each device. If the solution does not receive a heartbeat message within the expected time from the device, it assumes that there is a problem with the device.
8887

8988
A more complex implementation could include the information from [operations monitoring][lnk-devguide-opmon] to identify devices that are trying to connect or communicate but failing. When you implement the heartbeat pattern, make sure to check [IoT Hub Quotas and Throttles][lnk-quotas].

0 commit comments

Comments
 (0)