Skip to content

Commit ccef4ad

Browse files
committed
Updates to intro and .net article
1 parent 61a7f25 commit ccef4ad

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ ms.custom: mqtt, devx-track-csharp, devx-track-dotnet
1515

1616
# Get started with IoT Hub module identities and module identity twins
1717

18-
[Module identities and module identity twins](iot-hub-devguide-module-twins.md) are similar to Azure IoT Hub device identity and device twin, but provide finer granularity. While Azure IoT Hub device identity and device twin enable the back-end application to configure a device and provide visibility on the device's conditions, a module identity and module identity twin provide these capabilities for individual components of a device. On capable devices with multiple components, such as operating system devices or firmware devices, module identities and module identity twins allow for isolated configuration and conditions for each component.
18+
[Module identities and module identity twins](iot-hub-devguide-module-twins.md) are similar to Azure IoT Hub device identities and device twins, but provide finer granularity. While Azure IoT Hub device identities and device twins enable the back-end application to configure a device and provide visibility on the device's conditions, a module identity and module identity twin provide these capabilities for individual components of a device. On capable devices with multiple components, such as operating system devices or firmware devices, module identities and module identity twins allow for isolated configuration and conditions for each component.
1919

2020
[!INCLUDE [iot-hub-basic](../../includes/iot-hub-basic-whole.md)]
2121

2222
This article shows you how to develop two types of applications:
2323

24-
* Device apps can handle requests to update module desired properties and respond with changes to reported properties.
25-
* Service apps that can set new desired properties.
24+
* Device apps that view and update reported properties and handle requests to update module desired properties.
25+
* Service apps that can add modules and read and set new desired properties.
2626

2727
> [!NOTE]
2828
> This article is meant to complement [Azure IoT SDKs](iot-hub-devguide-sdks.md) samples that are referenced from within this article. You can use SDK tools to build both device and back-end applications.

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.author: kgremban
77
ms.service: iot-hub
88
ms.devlang: csharp
99
ms.topic: include
10-
ms.date: 09/03/2024
10+
ms.date: 10/02/2024
1111
ms.custom: mqtt, devx-track-csharp, devx-track-dotnet
1212
---
1313

@@ -34,22 +34,17 @@ Device client applications written in C# require the **Microsoft.Azure.Devices.C
3434
Add these `using` statements to use the device library.
3535

3636
```csharp
37-
using Microsoft.Azure.Devices;
38-
using Microsoft.Azure.Devices.Common.Exceptions;
37+
using Microsoft.Azure.Devices.Client;
38+
using Microsoft.Azure.Devices.Shared;
3939
```
4040

4141
### Connect to a device
4242

4343
The [ModuleClient](/dotnet/api/microsoft.azure.devices.client.moduleclient) class exposes all the methods required to interact with module identity twins from the device.
4444

45-
Connect to the device using the [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.client.moduleclient.createfromconnectionstring) method with the module connection string. The method connects using the default AMQP transport.
45+
Connect to the device using the [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.client.moduleclient.createfromconnectionstring) method with the module connection string. `CreateFromConnectionString` connects using the default AMQP transport.
4646

4747
```csharp
48-
using Microsoft.Azure.Devices.Client;
49-
using Microsoft.Azure.Devices.Shared;
50-
using System.Threading.Tasks;
51-
using Newtonsoft.Json;
52-
5348
static string ModuleConnectionString = "{Device module connection string}";
5449
private static ModuleClient _moduleClient = null;
5550

@@ -83,10 +78,10 @@ For example:
8378
```csharp
8479
try
8580
{
86-
Console.WriteLine("Sending sample start time as reported property");
87-
TwinCollection reportedProperties = new TwinCollection();
88-
reportedProperties["DateTimeLastAppLaunch"] = DateTime.UtcNow;
89-
await _moduleClient.UpdateReportedPropertiesAsync(reportedProperties);
81+
Console.WriteLine("Sending sample start time as reported property");
82+
TwinCollection reportedProperties = new TwinCollection();
83+
reportedProperties["DateTimeLastAppLaunch"] = DateTime.UtcNow;
84+
await _moduleClient.UpdateReportedPropertiesAsync(reportedProperties);
9085
}
9186
catch (Exception ex)
9287
{
@@ -141,12 +136,22 @@ The [RegistryManager](/dotnet/api/microsoft.azure.devices.registrymanager) class
141136

142137
This section describes how to create backend application code to:
143138

139+
* Add a module
144140
* Read and update module fields
145141

146142
### Add service NuGet Package
147143

148144
Backend service applications require the **Microsoft.Azure.Devices** NuGet package.
149145

146+
### Service using statements
147+
148+
Add these `using` statements to use the service library.
149+
150+
```csharp
151+
using Microsoft.Azure.Devices;
152+
using Microsoft.Azure.Devices.Shared;
153+
```
154+
150155
### Connect to IoT hub
151156

152157
Connect a backend application to a device using [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.registrymanager.createfromconnectionstring).
@@ -159,7 +164,6 @@ The SDK methods in this section require these shared access policy permissions:
159164
As a parameter to `CreateFromConnectionString`, supply a shared access policy connection string that includes these permissions. For more information about shared access policies, see [Control access to IoT Hub with shared access signatures](/azure/iot-hub/authenticate-authorize-sas).
160165

161166
```csharp
162-
using Microsoft.Azure.Devices;
163167
static RegistryManager registryManager;
164168
static string connectionString = "{IoT hub shared access policy connection string}";
165169
registryManager = RegistryManager.CreateFromConnectionString(connectionString);
@@ -195,11 +199,11 @@ Console.WriteLine("Generated module key: {0}", module.Authentication.SymmetricKe
195199

196200
Call [GetModuleAsync](/dotnet/api/microsoft.azure.devices.registrymanager.getmoduleasync) to retrieve current module identity twin fields into a [Module](/dotnet/api/microsoft.azure.devices.module) object.
197201

198-
The `Module` class includes [properties](/dotnet/api/microsoft.azure.devices.shared.twin?&#properties) that correspond to each section of a module. Use the `Module` class properties to view and update module identity twin fields. You can use the `Module` object properties to update multiple fields before writing the updates to the device using `UpdateModuleAsync`.
202+
The `Module` class includes [properties](/dotnet/api/microsoft.azure.devices.shared.twin?&#properties) that correspond to sections of an identity module twin. Use the `Module` class properties to view and update module identity twin fields. You can use the `Module` object properties to update multiple fields before writing the updates to the device using `UpdateModuleAsync`.
199203

200204
After making module identity twin field updates, call [UpdateModuleAsync](/dotnet/api/microsoft.azure.devices.registrymanager.updatemoduleasync) to write `Module` object field updates back to a device. Use `try` and `catch` logic coupled with an error handler to catch incorrectly formatted patch errors from `UpdateModuleAsync`.
201205

202-
This example retrieves a module into a `Module` object, updates the `module`, and then updates the module in IoT Hub using `UpdateModuleAsync`.
206+
This example retrieves a module into a `Module` object, updates the `module` `LastActivityTime` property, and then updates the module in IoT Hub using `UpdateModuleAsync`.
203207

204208
```csharp
205209
// Retrieve the module
@@ -221,8 +225,8 @@ catch (Exception e)
221225

222226
### Other module API
223227

224-
* [GetModulesOnDeviceAsync](/dotnet/api/microsoft.azure.devices.registrymanager.getmodulesondeviceasync) - Retrieves the module identities on a device.
225-
* [RemoveModuleAsync](/dotnet/api/microsoft.azure.devices.registrymanager.removemoduleasync) - Deletes a previously registered module from a device.
228+
* [GetModulesOnDeviceAsync](/dotnet/api/microsoft.azure.devices.registrymanager.getmodulesondeviceasync) - Retrieves the module identities on a device
229+
* [RemoveModuleAsync](/dotnet/api/microsoft.azure.devices.registrymanager.removemoduleasync) - Deletes a previously registered module from a device
226230

227231
### SDK service sample
228232

0 commit comments

Comments
 (0)