Skip to content

Commit b26b1b5

Browse files
authored
Merge pull request #96917 from dominicbetts/central-qs-updates
Update device tutorial
2 parents 8f9b9cf + 6a2c1f9 commit b26b1b5

File tree

1 file changed

+40
-32
lines changed

1 file changed

+40
-32
lines changed

articles/iot-central/preview/tutorial-connect-pnp-device.md

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Complete the [Create an Azure IoT Central application (preview features)](./quic
3131

3232
To complete this tutorial, you need to install the following software on your local machine:
3333

34-
* [Visual Studio (Community, Professional, or Enterprise)](https://visualstudio.microsoft.com/downloads/) - make sure that you include the **NuGet package manager** component and the **Desktop Development with C++** workload when you install Visual Studio.
34+
* [Build Tools for Visual Studio](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16) with **C++ build tools** and **Nuget package manager component** workloads. Or if you already have [Visual Studio (Community, Professional, or Enterprise)](https://visualstudio.microsoft.com/downloads/) 2019, 2017 or 2015 with same workloads installed.
3535
* [Git](https://git-scm.com/download/).
3636
* [CMake](https://cmake.org/download/) - when you install **CMake**, select the option **Add CMake to the system PATH**.
3737
* [Visual Studio Code](https://code.visualstudio.com/).
@@ -52,23 +52,27 @@ Use the following steps to install the Azure IoT Tools extension pack in VS Code
5252
5353
## Prepare the development environment
5454
55-
### Get Azure IoT device SDK for C
55+
In this tutorial, you use the [Vcpkg](https://github.com/microsoft/vcpkg) library manager to install the Azure IoT C device SDK in your development environment.
5656
57-
Prepare a development environment you can use to build the Azure IoT C device SDK.
57+
1. Open a command prompt. Execute the following command to install Vcpkg:
5858
59-
1. Open a command prompt. Execute the following command to clone the [Azure IoT C SDK](https://github.com/Azure/azure-iot-sdk-c) GitHub repository:
59+
```cmd
60+
git clone https://github.com/Microsoft/vcpkg.git
61+
cd vcpkg
6062
61-
```cmd/sh
62-
git clone https://github.com/Azure/azure-iot-sdk-c --recursive -b public-preview
63+
.\bootstrap-vcpkg.bat
6364
```
6465
65-
You should expect this operation to take several minutes to complete.
66+
Then, to hook up user-wide [integration](https://github.com/microsoft/vcpkg/blob/master/docs/users/integration.md), run the following command. The first time you run this command it requires administrative rights:
67+
68+
```cmd
69+
.\vcpkg.exe integrate install
70+
```
6671
67-
1. Create a `central_app` folder in the root of the local clone of the repository. You use this folder for the device model files and device code stub.
72+
1. Install Azure IoT C device SDK Vcpkg:
6873
69-
```cmd/sh
70-
cd azure-iot-sdk-c
71-
mkdir central_app
74+
```cmd
75+
.\vcpkg.exe install azure-iot-sdk-c[public-preview,use_prov_client]
7276
```
7377
7478
## Generate device key
@@ -86,7 +90,7 @@ To connect a device to an IoT Central application, you need a device key. To gen
8690
1. Open a command prompt and run the following command to generate a device key:
8791
8892
```cmd/sh
89-
dps-keygen -di:mxchip-01 -mk:{Primary Key from previous step}
93+
dps-keygen -di:mxchip-001 -mk:{Primary Key from previous step}
9094
```
9195
9296
Make a note of the generated _device key_, you use this value in a later step in this tutorial.
@@ -95,7 +99,7 @@ To connect a device to an IoT Central application, you need a device key. To gen
9599
96100
In this tutorial, you use the public DCM for an MxChip IoT DevKit device. You don't need an actual DevKit device to run the code, in this tutorial you compile the code to run on Windows.
97101
98-
1. Open `azure-iot-sdk-c\central_app` folder with VS Code.
102+
1. Create a folder called `central_app` and open it in VS Code.
99103
100104
1. Use **Ctrl+Shift+P** to open the command palette, enter **IoT Plug and Play**, and select **Open Model Repository**. Select **Public repository**. VS Code shows a list of the DCMs in the public model repository.
101105
@@ -121,10 +125,12 @@ Now you have the **MXChip IoT DevKit** DCM and its associated interfaces, you ca
121125
122126
1. Choose **ANSI C** as your language.
123127
124-
1. Choose **CMake Project** as your project type. Don't choose **MXChip IoT DevKit Project**, this option is for when you have a real DevKit device.
125-
126128
1. Choose **Via DPS (Device Provisioning Service) symmetric key** as the connection method.
127129
130+
1. Choose **CMake Project on Windows** as your project type. Don't choose **MXChip IoT DevKit Project**, this option is for when you have a real DevKit device.
131+
132+
1. Choose **Via Vcpkg** as the way to include the SDK.
133+
128134
1. VS Code opens a new window with generated device code stub files in the `devkit_device` folder.
129135
130136
![Generated device code](./media/tutorial-connect-pnp-device/generated-code.png)
@@ -133,35 +139,37 @@ Now you have the **MXChip IoT DevKit** DCM and its associated interfaces, you ca
133139
134140
You use the device SDK to build the generated device code stub. The application you build simulates an **MXChip IoT DevKit** device and connects to your IoT Central application. The application sends telemetry and properties, and receives commands.
135141
136-
1. In VS Code, open the `CMakeLists.txt` file in the `azure-iot-sdk-c` folder. Make sure you open the `CMakeLists.txt` file in the `azure-iot-sdk-c` folder, not the one in the `devkit_device` folder.
142+
1. At a command prompt, create a `cmake` subdirectory in the `devkit_device` folder, and navigate to that folder:
137143
138-
1. Add the line below at the bottom of the `CMakeLists.txt` file to include the device code stub folder when compiling:
139-
140-
```txt
141-
add_subdirectory(central_app/devkit_device)
144+
```cmd
145+
mkdir cmake
146+
cd cmake
142147
```
143148
144-
1. Create a `cmake` folder in the `azure-iot-sdk-c` folder, and navigate to that folder at a command prompt:
149+
1. Run the following commands to build the generated code stub. Replace the `<directory of your Vcpkg repo>` placeholder with the path to your copy of the **Vcpkg** repository:
145150
146-
```cmd\sh
147-
mkdir cmake
148-
cd cmake
151+
```cmd
152+
cmake .. -G "Visual Studio 16 2019" -A Win32 -Duse_prov_client=ON -Dhsm_type_symm_key:BOOL=ON -DCMAKE_TOOLCHAIN_FILE="<directory of your Vcpkg repo>\scripts\buildsystems\vcpkg.cmake"
153+
154+
cmake --build . -- /p:Configuration=Release
149155
```
150156
151-
1. Run the following commands to build the device SDK and the generated code stub:
157+
If you're using Visual Studio 2017 or 2015, you need to specify the CMake generator based on the build tools you're using:
152158
153-
```cmd\sh
154-
cmake .. -Duse_prov_client=ON -Dhsm_type_symm_key:BOOL=ON
155-
cmake --build . -- /m /p:Configuration=Release
159+
```cmd
160+
# Either
161+
cmake .. -G "Visual Studio 15 2017" -Duse_prov_client=ON -Dhsm_type_symm_key:BOOL=ON -DCMAKE_TOOLCHAIN_FILE="<directory of your Vcpkg repo>\scripts\buildsystems\vcpkg.cmake"
162+
# or
163+
cmake .. -G "Visual Studio 14 2015" -Duse_prov_client=ON -Dhsm_type_symm_key:BOOL=ON -DCMAKE_TOOLCHAIN_FILE="<directory of your Vcpkg repo>\scripts\buildsystems\vcpkg.cmake"
156164
```
157165
158-
1. After the build completes successfully, at the same command prompt run your application. Replace `scopeid`, `primarykey` with the values you noted previously :
166+
1. After the build completes successfully, at the same command prompt run your application. Replace `<scopeid>` and `<devicekey>` with the values you noted previously:
159167
160-
```cmd\sh
161-
.\central_app\devkit_device\Release\devkit_device.exe scopeid primarykey mxchip-001
168+
```cmd
169+
.\Release\devkit_device.exe mxchip-001 <scopeid> <devicekey>
162170
```
163171
164-
1. The device application starts sending data to your IoT Central application.
172+
1. The device application starts sending data to IoT Hub. Sometimes you see the error `Error registering device for DPS` the first time you run the previous command. If you see this error, retry the command.
165173
166174
## View the device
167175

0 commit comments

Comments
 (0)