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/how-to-device-twins.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,9 +67,9 @@ This article shows you how to:
67
67
68
68
***A registered device**. Register one in the [Azure portal](create-connect-device.md).
69
69
70
-
* Make sure that port 8883 is open in your firewall. The device sample in this article uses MQTT protocol, which communicates over port 8883. This port may be blocked in some corporate and educational network environments. For more information and ways to work around this issue, see [Connecting to IoT Hub (MQTT)](../iot/iot-mqtt-connect-to-iot-hub.md#connecting-to-iot-hub).
70
+
* Make sure that **port 8883** is open in your firewall. The device sample in this article uses MQTT protocol, which communicates over port 8883. This port may be blocked in some corporate and educational network environments. For more information and ways to work around this issue, see [Connecting to IoT Hub (MQTT)](../iot/iot-mqtt-connect-to-iot-hub.md#connecting-to-iot-hub).
71
71
72
-
* IoT Hub service connection string
72
+
***IoT Hub service connection string**
73
73
74
74
In this article you create a back-end service that adds desired properties to a device twin and then queries the identity registry to find all devices with reported properties that have been updated accordingly. Your service needs the **service connect** permission to modify desired properties of a device twin, and it needs the **registry read** permission to query the identity registry. There is no default shared access policy that contains only these two permissions, so you need to create one.
This section describes how to use the .NET/C# SDK to create device and backend service application code.
17
+
18
+
Visual Studio is required to use the .NET/C# SDK.
19
+
14
20
## Create a device application
15
21
16
22
Device applications can read and write twin reported properties, and be notified of desired twin property changes that are set by a backend application or IoT Hub.
@@ -37,7 +43,7 @@ The [DeviceClient](/dotnet/api/microsoft.azure.devices.client.deviceclient) clas
37
43
38
44
Connect to the device using the [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.client.deviceclient.createfromconnectionstring?#microsoft-azure-devices-client-deviceclient-createfromconnectionstring(system-string)) method along with device connection string and the connection transport protocol.
39
45
40
-
The `CreateFromConnectionString`[TransportType](/dotnet/api/microsoft.azure.devices.client.transporttype) parameter supports `Mqtt`, `Mqtt_WebSocket_Only`, `Mqtt_Tcp_Only`, `Amqp`, `Amqp_WebSocket_Only`, and `Amqp_Tcp_Only`. `Http1` is not supported for device twin updates.
46
+
The `CreateFromConnectionString`[TransportType](/dotnet/api/microsoft.azure.devices.client.transporttype)transport protocol parameter supports `Mqtt`, `Mqtt_WebSocket_Only`, `Mqtt_Tcp_Only`, `Amqp`, `Amqp_WebSocket_Only`, and `Amqp_Tcp_Only`. `Http1` is not supported for device twin updates.
41
47
42
48
This example connects to a device using the `Mqtt` transport protocol.
43
49
@@ -92,7 +98,7 @@ catch (Exception ex)
92
98
93
99
### Create a desired property update callback handler
94
100
95
-
You can create a desired property update callback handler that executes when the desired property is changed in the device by passing the callback handler method name to [SetDesiredPropertyUpdateCallbackAsync](/dotnet/api/microsoft.azure.devices.client.deviceclient.setdesiredpropertyupdatecallbackasync?#microsoft-azure-devices-client-deviceclient-setdesiredpropertyupdatecallbackasync(microsoft-azure-devices-client-desiredpropertyupdatecallback-system-object)).
101
+
You can create a desired property update callback handler that executes when a desired property is changed in the device by passing the callback handler method name to [SetDesiredPropertyUpdateCallbackAsync](/dotnet/api/microsoft.azure.devices.client.deviceclient.setdesiredpropertyupdatecallbackasync?#microsoft-azure-devices-client-deviceclient-setdesiredpropertyupdatecallbackasync(microsoft-azure-devices-client-desiredpropertyupdatecallback-system-object)).
96
102
97
103
For example, this call sets up the system to notify a method named`OnDesiredPropertyChangedAsync` whenever a desired property is changed.
98
104
@@ -132,7 +138,10 @@ The SDK includes this [TwinSample](https://github.com/Azure/azure-iot-sdk-csharp
132
138
133
139
## Create a backend application
134
140
135
-
A backend application runs independently of a device and IoT Hub, and connects to a device through IoT Hub.
141
+
A backend application:
142
+
143
+
* Connects to a device through IoT Hub
144
+
* Can read device reported and desired properties, write device desired properties, and run device queries
136
145
137
146
The [RegistryManager](/dotnet/api/microsoft.azure.devices.registrymanager) class exposes all methods required to create a backend application to interact with device twins from the service.
138
147
@@ -174,7 +183,7 @@ After making twin field updates, call [UpdateTwinAsync](/dotnet/api/microsoft.az
174
183
175
184
Use the device twin [Tags](/dotnet/api/microsoft.azure.devices.shared.twin.tags?#microsoft-azure-devices-shared-twin-tags) property to read and write device tag information.
176
185
177
-
##### Write using a Twin object
186
+
##### Update using a Twin object
178
187
179
188
This example creates a `location` tag patch, assigns it to the `Twin` object using the `Tags` property, and then applies the patch using `UpdateTwinAsync`.
180
189
@@ -207,7 +216,7 @@ catch (Exception e)
207
216
}
208
217
```
209
218
210
-
##### Write using a JSON string
219
+
##### Update using a JSON string
211
220
212
221
You can also create and apply a device twin information update patch that contains a block of field updates, including different field types such as tags mixed with desired properties. IoT Hub parses and applies the patch if it is correctly formatted and the fields are updatable. For example, device twin reported properties cannot be updated by a backend application and the patch for these fields are not be applied.
0 commit comments