Skip to content

Commit cc2d190

Browse files
authored
Merge pull request #83624 from TimShererWithAquent/us1546060b
Freshness pass, various edits, per 1546060
2 parents fe4afc4 + e4184ae commit cc2d190

14 files changed

+82
-64
lines changed

articles/iot-hub/iot-hub-csharp-csharp-module-twin-getstarted.md

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ms.service: iot-hub
66
services: iot-hub
77
ms.devlang: csharp
88
ms.topic: conceptual
9-
ms.date: 04/26/2018
9+
ms.date: 08/07/2019
1010
ms.author: menchi
1111
---
1212

@@ -15,24 +15,24 @@ ms.author: menchi
1515
[!INCLUDE [iot-hub-selector-module-twin-getstarted](../../includes/iot-hub-selector-module-twin-getstarted.md)]
1616

1717
> [!NOTE]
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 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.
1919
2020
At the end of this tutorial, you have two .NET console apps:
2121

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

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

2626
> [!NOTE]
2727
> 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).
2828
29-
To complete this tutorial, you need the following:
29+
To complete this tutorial, you need the following prerequisites:
3030

3131
* Visual Studio.
3232

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

35-
## Create an IoT hub
35+
## Create a hub
3636

3737
[!INCLUDE [iot-hub-include-create-hub](../../includes/iot-hub-include-create-hub.md)]
3838

@@ -48,21 +48,25 @@ To complete this tutorial, you need the following:
4848

4949
In this section, you create a .NET console app on your simulated device that updates the module twin reported properties.
5050

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

53-
![Create a visual studio project](./media/iot-hub-csharp-csharp-module-twin-getstarted/update-twins-csharp1.png)
53+
![Azure portal module detail](./media/iot-hub-csharp-csharp-module-twin-getstarted/module-identity-detail.png)
5454

55-
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**.
5656

57-
![Install Azure IoT Hub .NET service SDK V1.16.0-preview-005](./media/iot-hub-csharp-csharp-module-twin-getstarted/install-sdk.png)
57+
1. Name the project *UpdateModuleTwinReportedProperties*. For **Solution**, select **Add to solution**. Make sure the .NET Framework version is 4.6.1 or later.
5858

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+
![Create a Visual Studio project](./media/iot-hub-csharp-csharp-module-twin-getstarted/configure-update-twins-csharp1.png)
6060

61-
![Azure portal module detail](./media/iot-hub-csharp-csharp-module-twin-getstarted/module-detail.png)
61+
1. Select **Create** to create your project.
6262

63-
4. **Create UpdateModuleTwinReportedProperties console app**
63+
1. In Visual Studio, open **Tools** > **NuGet Package Manager** > **Manage NuGet Packages for Solution**. Select the **Browse** tab.
6464

65-
Add the following `using` statements at the top of the **Program.cs** file:
65+
1. Search for and select **Microsoft.Azure.Devices.Client**, and then select **Install**.
66+
67+
![Install Azure IoT Hub .NET service SDK current version](./media/iot-hub-csharp-csharp-module-twin-getstarted/install-client-sdk.png)
68+
69+
1. Add the following `using` statements at the top of the **Program.cs** file:
6670

6771
```csharp
6872
using Microsoft.Azure.Devices.Client;
@@ -71,11 +75,10 @@ In this section, you create a .NET console app on your simulated device that upd
7175
using Newtonsoft.Json;
7276
```
7377

74-
Add the following fields to the **Program** class. Replace the placeholder value with the module connection string.
78+
1. Add the following fields to the **Program** class. Replace the placeholder value with the module connection string.
7579

7680
```csharp
77-
private const string ModuleConnectionString =
78-
"<Your module connection string>";
81+
private const string ModuleConnectionString = "<Your module connection string>";
7982
private static ModuleClient Client = null;
8083
static void ConnectionStatusChangeHandler(ConnectionStatus status,
8184
ConnectionStatusChangeReason reason)
@@ -85,7 +88,7 @@ In this section, you create a .NET console app on your simulated device that upd
8588
}
8689
```
8790

88-
Add the following method **OnDesiredPropertyChanged** to the **Program** class:
91+
1. Add the following method **OnDesiredPropertyChanged** to the **Program** class:
8992

9093
```csharp
9194
private static async Task OnDesiredPropertyChanged(TwinCollection desiredProperties,
@@ -103,7 +106,7 @@ In this section, you create a .NET console app on your simulated device that upd
103106
}
104107
```
105108

106-
Finally, add the following lines to the **Main** method:
109+
1. Add the following lines to the **Main** method:
107110

108111
```csharp
109112
static void Main(string[] args)
@@ -143,7 +146,7 @@ In this section, you create a .NET console app on your simulated device that upd
143146

144147
This code sample shows you how to retrieve the module twin and update reported properties with AMQP protocol. In public preview, we only support AMQP for module twin operations.
145148

146-
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** method to send an event to IoT Hub from your module. Place these lines below the `try catch` block.
147150

148151
```csharp
149152
Byte[] bytes = new Byte[2];
@@ -156,11 +159,20 @@ In this section, you create a .NET console app on your simulated device that upd
156159

157160
## Run the apps
158161

159-
You are now ready to run the apps. In Visual Studio, in Solution Explorer, right-click your solution, and then click **Set StartUp projects**. Select **Multiple startup projects**, and then select **Start** as the action for the console app. And then press F5 to start the app.
162+
You can now run the apps.
163+
164+
1. In Visual Studio, in **Solution Explorer**, right-click your solution, and then select **Set StartUp projects**.
165+
166+
1. Under **Common Properties**, select **Startup Project.**
167+
168+
1. Select **Multiple startup projects**, and then select **Start** as the action for the apps, and **OK** to accept your changes.
169+
170+
1. Press **F5** to start the apps.
160171

161172
## Next steps
162173

163174
To continue getting started with IoT Hub and to explore other IoT scenarios, see:
164175

165176
* [Getting started with device management](iot-hub-node-node-device-management-get-started.md)
177+
166178
* [Getting started with IoT Edge](../iot-edge/tutorial-simulate-device-linux.md)
29.5 KB
Loading
38 KB
Loading
45.2 KB
Loading

includes/iot-hub-get-started-create-module-identity-csharp.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,48 @@ services: iot-hub
55
author: chrissie926
66
ms.service: iot-hub
77
ms.topic: include
8-
ms.date: 04/26/2018
8+
ms.date: 08/07/2019
99
ms.author: menchi
1010
ms.custom: include file
1111
---
1212

1313
## Create a module identity
1414

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

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

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**.
1920

20-
![Create a visual studio solution](./media/iot-hub-get-started-create-module-identity-csharp/create-identities-csharp1.JPG)
21+
1. In **Create a new project**, select **Console App (.NET Framework)**.
2122

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

24-
![Install Azure IoT Hub .NET service SDK V1.16.0-preview-001](./media/iot-hub-get-started-create-module-identity-csharp/install-sdk.png)
25+
![Enter name and framework for your Visual Studio solution](./media/iot-hub-get-started-create-module-identity-csharp/configure-createidentities-project.png)
2526

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+
![Install Azure IoT Hub .NET service SDK current version](./media/iot-hub-get-started-create-module-identity-csharp/install-service-sdk.png)
32+
33+
1. Add the following `using` statements at the top of the **Program.cs** file:
2734

2835
```csharp
2936
using Microsoft.Azure.Devices;
3037
using Microsoft.Azure.Devices.Common.Exceptions;
3138
```
3239

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

3542
```csharp
3643
const string connectionString = "<replace_with_iothub_connection_string>";
3744
const string deviceID = "myFirstDevice";
3845
const string moduleID = "myFirstModule";
3946
```
4047

41-
5. Add the following code to the **Main** class.
42-
48+
1. Add the following code to the **Main** class.
49+
4350
```csharp
4451
static void Main(string[] args)
4552
{
@@ -48,7 +55,7 @@ In this section, you create a .NET console app that creates a device identity an
4855
}
4956
```
5057

51-
6. Add the following methods to the **Program** class:
58+
1. Add the following methods to the **Program** class:
5259

5360
```csharp
5461
private static async Task AddDeviceAsync()
@@ -90,13 +97,13 @@ In this section, you create a .NET console app that creates a device identity an
9097
}
9198
```
9299

93-
The AddDeviceAsync() method creates a device identity with ID **myFirstDevice**. (If that device ID already exists in the identity registry, the code simply retrieves the existing device information.) The app then displays the primary key for that identity. You use this key in the simulated device app to connect to your IoT hub.
100+
The `AddDeviceAsync` method creates a device identity with ID **myFirstDevice**. If that device ID already exists in the identity registry, the code simply retrieves the existing device information. The app then displays the primary key for that identity. You use this key in the simulated device app to connect to your hub.
94101

95-
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 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.
96103

97104
[!INCLUDE [iot-hub-pii-note-naming-device](iot-hub-pii-note-naming-device.md)]
98105

99-
7. Run this application, and make a note of the device key and module key.
106+
1. Run this app, and make a note of the device key and module key.
100107

101108
> [!NOTE]
102-
> The IoT Hub identity registry only stores device and module identities to enable secure access to the IoT hub. The identity registry stores device IDs and keys to use as security credentials. The identity registry also stores an enabled/disabled flag for 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+
> The IoT Hub identity registry only stores device and module identities to enable secure access to the hub. The identity registry stores device IDs and keys to use as security credentials. The identity registry also stores an enabled/disabled flag for 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).

includes/iot-hub-howto-module-twin-shared-access-policy-text.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ ms.custom: include file
1111
---
1212
<!-- This contains intro text for the "Get an IoT hub connection string" section in the iot-hub-lang-lang-module-twin-getstarted.md files-->
1313

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.

includes/iot-hub-howto-twin-shared-access-policy-text.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: robinsh
55
ms.service: iot-hub
66
services: iot-hub
77
ms.topic: include
8-
ms.date: 07/17/2019
8+
ms.date: 08/07/2019
99
ms.author: robinsh
1010
ms.custom: include file
1111
---

0 commit comments

Comments
 (0)