Skip to content

Commit 73e20e3

Browse files
committed
Updates
1 parent 8b345c7 commit 73e20e3

File tree

4 files changed

+124
-98
lines changed

4 files changed

+124
-98
lines changed

articles/iot-hub/how-to-device-twins.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ This article shows you how to:
6767

6868
* **A registered device**. Register one in the [Azure portal](create-connect-device.md).
6969

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).
7171

72-
* IoT Hub service connection string
72+
* **IoT Hub service connection string**
7373

7474
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.
7575

includes/iot-hub-howto-device-twins-dotnet.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ ms.date: 07/12/2024
1111
ms.custom: mqtt, devx-track-csharp, devx-track-dotnet
1212
---
1313

14+
## Overview
15+
16+
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+
1420
## Create a device application
1521

1622
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
3743

3844
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.
3945

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.
4147

4248
This example connects to a device using the `Mqtt` transport protocol.
4349

@@ -92,7 +98,7 @@ catch (Exception ex)
9298

9399
### Create a desired property update callback handler
94100

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)).
96102

97103
For example, this call sets up the system to notify a method named`OnDesiredPropertyChangedAsync` whenever a desired property is changed.
98104

@@ -132,7 +138,10 @@ The SDK includes this [TwinSample](https://github.com/Azure/azure-iot-sdk-csharp
132138

133139
## Create a backend application
134140

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
136145

137146
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.
138147

@@ -174,7 +183,7 @@ After making twin field updates, call [UpdateTwinAsync](/dotnet/api/microsoft.az
174183

175184
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.
176185

177-
##### Write using a Twin object
186+
##### Update using a Twin object
178187

179188
This example creates a `location` tag patch, assigns it to the `Twin` object using the `Tags` property, and then applies the patch using `UpdateTwinAsync`.
180189

@@ -207,7 +216,7 @@ catch (Exception e)
207216
}
208217
```
209218

210-
##### Write using a JSON string
219+
##### Update using a JSON string
211220

212221
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.
213222

0 commit comments

Comments
 (0)