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
> [Module identities and module 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 provides visibility on the device’s conditions, a module identity and module twin provide these capabilities for individual components of a device. On capable devices with multiple components, such as operating system based devices or firmware devices, it allows for isolated configuration and conditions for each component.
18
+
> [Module identities and module 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 twin provide these capabilities for individual components of a device. On capable devices with multiple components, such as operating system based devices or firmware devices, module identities and module twins allow for isolated configuration and conditions for each component.
19
19
20
20
At the end of this tutorial, you have two .NET console apps:
21
21
22
-
***CreateIdentities**, which creates a device identity, a module identity and associated security key to connect your device and module clients.
22
+
***CreateIdentities**. This app creates a device identity, a module identity, and associated security key to connect your device and module clients.
23
23
24
-
***UpdateModuleTwinReportedProperties**, which sends updated module twin reported properties to your IoT Hub.
24
+
***UpdateModuleTwinReportedProperties**. This app sends updated module twin reported properties to your IoT hub.
25
25
26
26
> [!NOTE]
27
27
> For information about the Azure IoT SDKs that you can use to build both applications to run on devices, and your solution back end, see [Azure IoT SDKs](iot-hub-devguide-sdks.md).
28
28
29
-
To complete this tutorial, you need the following:
29
+
To complete this tutorial, you need the following prerequisites:
30
30
31
31
* Visual Studio.
32
32
33
-
* An active Azure account. (If you don't have an account, you can create a [free account](https://azure.microsoft.com/pricing/free-trial/) in just a couple of minutes.)
33
+
* An active Azure account. If you don't have an account, you can create a [free account](https://azure.microsoft.com/pricing/free-trial/) in just a couple of minutes.
@@ -48,21 +48,25 @@ To complete this tutorial, you need the following:
48
48
49
49
In this section, you create a .NET console app on your simulated device that updates the module twin reported properties.
50
50
51
-
1.**Create a Visual Studio project:** In Visual Studio, add a Visual C# Windows Classic Desktop project to the existing solution by using the **Console App (.NET Framework)** project template. Make sure the .NET Framework version is 4.6.1 or later. Name the project **UpdateModuleTwinReportedProperties**.
51
+
Before you begin, get your module connection string. Sign in to the [Azure portal](https://portal.azure.com/). Navigate to your hub and select **IoT Devices**. Find **myFirstDevice**. Select **myFirstDevice** to open it, and then select **myFirstModule** to open it. In **Module Identity Details**, copy the **Connection string (primary key)** when needed in the following procedure.
52
52
53
-

2.**Install the latest Azure IoT Hub .NET device SDK:** Module identity and module twin is in public preview. It's only available in the IoT Hub prerelease device SDKs. In Visual Studio, open tools > Nuget package manager > manage Nuget packages for solution. Search Microsoft.Azure.Devices.Client. Make sure you've checked include prerelease check box. Select the latest version and install. Now you have access to all the module features.
55
+
1.In Visual Studio, add a new project to your solution by selecting **File** > **New** > **Project**. In Create a new project, select **Console App (.NET Framework)**, and select **Next**.
56
56
57
-

57
+
1. Name the project *UpdateModuleTwinReportedProperties*. For **Solution**, select **Add to solution**. Make sure the .NET Framework version is 4.6.1 or later.
58
58
59
-
3.**Get your module connection string** -- now if you sign in to [Azure portal](https://portal.azure.com/). Navigate to your IoT Hub and click IoT Devices. Find myFirstDevice, open it and you see myFirstModule was successfully created. Copy the module connection string. It is needed in the next step.
59
+

5. In addition to the above **Main** method, you can add below code block to send event to IoT Hub from your module:
149
+
1. Optionally, you can add these statements to the **Main** methodto send an event to IoT Hub from your module. Place these lines below the `try catch` block.
147
150
148
151
```csharp
149
152
Byte[] bytes = new Byte[2];
@@ -156,11 +159,20 @@ In this section, you create a .NET console app on your simulated device that upd
156
159
157
160
## Run the apps
158
161
159
-
Youarenowreadytoruntheapps. InVisualStudio, inSolutionExplorer, right-clickyoursolution, andthenclick**SetStartUpprojects**. Select**Multiplestartupprojects**, andthenselect**Start**astheactionfor the console app. And then press F5 to start the app.
Copy file name to clipboardExpand all lines: includes/iot-hub-get-started-create-module-identity-csharp.md
+22-15Lines changed: 22 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,41 +5,48 @@ services: iot-hub
5
5
author: chrissie926
6
6
ms.service: iot-hub
7
7
ms.topic: include
8
-
ms.date: 04/26/2018
8
+
ms.date: 08/07/2019
9
9
ms.author: menchi
10
10
ms.custom: include file
11
11
---
12
12
13
13
## Create a module identity
14
14
15
-
In this section, you create a .NET console app that creates a device identity and a module identity in the identity registry in your IoT hub. A device or module cannot connect to IoT hub unless it has an entry in the identity registry. For more information, see the [Identity Registry section of the IoT Hub developer guide](../articles/iot-hub/iot-hub-devguide-identity-registry.md). When you run this console app, it generates a unique ID and key for both device and module. Your device and module use these values to identify itself when it sends device-to-cloud messages to IoT Hub. The IDs are case-sensitive.
15
+
In this section, you create a .NET console app that creates a device identity and a module identity in the identity registry in your hub. A device or module can't connect to hub unless it has an entry in the identity registry. For more information, see the [Identity Registry section of the IoT Hub developer guide](../articles/iot-hub/iot-hub-devguide-identity-registry.md).
16
16
17
+
When you run this console app, it generates a unique ID and key for both device and module. Your device and module use these values to identify themselves when it sends device-to-cloud messages to IoT Hub. The IDs are case-sensitive.
17
18
18
-
1.**Create a Visual Studio project** - In Visual Studio, add a Visual C# Windows Classic Desktop project to a new solution by using the **Console App (.NET Framework)**project template. Make sure the .NET Framework version is 4.6.1 or later. Name the project **CreateIdentities** and name the solution **IoTHubGetStarted**.
19
+
1.Open Visual Studio, and select **Create a new project**.
19
20
20
-

21
+
1. In **Create a new project**, select **Console App (.NET Framework)**.
21
22
22
-
2.**Install Azure IoT Hub .NET service SDK V1.16.0-preview-001** - Module identity and module twin is in public preview. It's only available in the IoT Hub prerelease service SDKs. In Visual Studio, open tools > Nuget package manager > manage Nuget packages for solution. Search Microsoft.Azure.Devices. Make sure you've checked include prerelease check box. Select version 1.16.0-preview-001 and install. Now you have access to all the module features.
23
+
1. Select **Next** to open **Configure your new project**. Name the project *CreateIdentities* and name the solution*IoTHubGetStarted*. Make sure the .NET Framework version is 4.6.1 or later.
23
24
24
-

25
+

25
26
26
-
3. Add the following `using` statements at the top of the **Program.cs** file:
27
+
1. In Visual Studio, open **Tools** > **NuGet Package Manager** > **Manage NuGet Packages for Solution**. Select the **Browse** tab.
28
+
29
+
1. Search for **Microsoft.Azure.Devices**. Select it and then select **Install**.
30
+
31
+

32
+
33
+
1. Add the following `using` statements at the top of the **Program.cs** file:
27
34
28
35
```csharp
29
36
usingMicrosoft.Azure.Devices;
30
37
usingMicrosoft.Azure.Devices.Common.Exceptions;
31
38
```
32
39
33
-
4. Add the following fields to the **Program** class. Replace the placeholder value with the IoT Hub connection string for the hub that you created in the previous section.
40
+
1. Add the following fields to the **Program** class. Replace the placeholder value with the IoT Hub connection string for the hub that you created in the previous section.
@@ -48,7 +55,7 @@ In this section, you create a .NET console app that creates a device identity an
48
55
}
49
56
```
50
57
51
-
6. Add the following methods to the **Program** class:
58
+
1. Add the following methods to the **Program** class:
52
59
53
60
```csharp
54
61
privatestaticasyncTaskAddDeviceAsync()
@@ -90,13 +97,13 @@ In this section, you create a .NET console app that creates a device identity an
90
97
}
91
98
```
92
99
93
-
TheAddDeviceAsync()methodcreatesadeviceidentitywithID**myFirstDevice**. (IfthatdeviceIDalreadyexistsintheidentityregistry, thecodesimplyretrievestheexistingdeviceinformation.)Theappthendisplaystheprimarykeyfor that identity. You use this key in the simulated device app to connect to your IoT hub.
100
+
The`AddDeviceAsync`methodcreatesadeviceidentitywithID**myFirstDevice**. IfthatdeviceIDalreadyexistsintheidentityregistry, thecodesimplyretrievestheexistingdeviceinformation. Theappthendisplaystheprimarykeyfor that identity. You use this key in the simulated device app to connect to your hub.
94
101
95
-
The AddModuleAsync()methodcreatesamoduleidentitywithID**myFirstModule**underdevice**myFirstDevice**. (IfthatmoduleIDalreadyexistsintheidentityregistry, thecodesimplyretrievestheexistingmoduleinformation.)Theappthendisplaystheprimarykeyfor that identity. You use this key in the simulated module app to connect to your IoT hub.
102
+
The `AddModuleAsync` method creates a module identity with ID **myFirstModule** under device **myFirstDevice**. If that module ID already exists in the identity registry, the code simply retrieves the existing module information. The app then displays the primary key for that identity. You use this key in the simulated module app to connect to your hub.
>TheIoTHubidentityregistryonlystoresdeviceandmoduleidentitiestoenablesecureaccesstotheIoThub. TheidentityregistrystoresdeviceIDsandkeystouseassecuritycredentials. Theidentityregistryalsostoresanenabled/disabledflagfor each device that you can use to disable access for that device. If your application needs to store other device-specific metadata, it should use an application-specific store. There is no enabled/disabled flag for module identities. For more information, see [IoT Hub developer guide](../articles/iot-hub/iot-hub-devguide-identity-registry.md).
109
+
>TheIoTHubidentityregistryonlystoresdeviceandmoduleidentitiestoenablesecureaccesstothehub. TheidentityregistrystoresdeviceIDsandkeystouseassecuritycredentials. Theidentityregistryalsostoresanenabled/disabledflagfor each device that you can use to disable access for that device. If your app needs to store other device-specific metadata, it should use an application-specific store. There is no enabled/disabled flag for module identities. For more information, see [IoT Hub developer guide](../articles/iot-hub/iot-hub-devguide-identity-registry.md).
Copy file name to clipboardExpand all lines: includes/iot-hub-howto-module-twin-shared-access-policy-text.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,4 +11,4 @@ ms.custom: include file
11
11
---
12
12
<!-- This contains intro text for the "Get an IoT hub connection string" section in the iot-hub-lang-lang-module-twin-getstarted.md files-->
13
13
14
-
In this article, you create a backend service that adds a device in the identity registry and then adds a module to that device. To perform these operations, your service requires the **registry write** permission. By default, every IoT Hub is created with a shared access policy named **registryReadWrite** that grants this permission.
14
+
In this article, you create a back-end service that adds a device in the identity registry and then adds a module to that device. Your service requires the **registry write** permission. By default, every IoT hub is created with a shared access policy named **registryReadWrite** that grants this permission.
0 commit comments