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
# Get started with IoT Hub module identities and module identity twins
17
17
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.
This article shows you how to develop two types of applications:
23
23
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.
26
26
27
27
> [!NOTE]
28
28
> 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.
@@ -34,22 +34,17 @@ Device client applications written in C# require the **Microsoft.Azure.Devices.C
34
34
Add these `using` statements to use the device library.
35
35
36
36
```csharp
37
-
usingMicrosoft.Azure.Devices;
38
-
usingMicrosoft.Azure.Devices.Common.Exceptions;
37
+
usingMicrosoft.Azure.Devices.Client;
38
+
usingMicrosoft.Azure.Devices.Shared;
39
39
```
40
40
41
41
### Connect to a device
42
42
43
43
The [ModuleClient](/dotnet/api/microsoft.azure.devices.client.moduleclient) class exposes all the methods required to interact with module identity twins from the device.
44
44
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.
@@ -141,12 +136,22 @@ The [RegistryManager](/dotnet/api/microsoft.azure.devices.registrymanager) class
141
136
142
137
This section describes how to create backend application code to:
143
138
139
+
* Add a module
144
140
* Read and update module fields
145
141
146
142
### Add service NuGet Package
147
143
148
144
Backend service applications require the **Microsoft.Azure.Devices** NuGet package.
149
145
146
+
### Service using statements
147
+
148
+
Add these `using` statements to use the service library.
149
+
150
+
```csharp
151
+
usingMicrosoft.Azure.Devices;
152
+
usingMicrosoft.Azure.Devices.Shared;
153
+
```
154
+
150
155
### Connect to IoT hub
151
156
152
157
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:
159
164
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).
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.
197
201
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`.
199
203
200
204
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`.
201
205
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`.
203
207
204
208
```csharp
205
209
// Retrieve the module
@@ -221,8 +225,8 @@ catch (Exception e)
221
225
222
226
### Other module API
223
227
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
0 commit comments