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
Copy file name to clipboardExpand all lines: articles/iot-central/preview/tutorial-connect-pnp-device.md
+40-32Lines changed: 40 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ Complete the [Create an Azure IoT Central application (preview features)](./quic
31
31
32
32
To complete this tutorial, you need to install the following software on your local machine:
33
33
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.
35
35
*[Git](https://git-scm.com/download/).
36
36
*[CMake](https://cmake.org/download/) - when you install **CMake**, select the option **Add CMake to the system PATH**.
37
37
*[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
52
52
53
53
## Prepare the development environment
54
54
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.
56
56
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:
58
58
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:
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
+
```
66
71
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.
@@ -86,7 +90,7 @@ To connect a device to an IoT Central application, you need a device key. To gen
86
90
1. Open a command prompt and run the following command to generate a device key:
87
91
88
92
```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}
90
94
```
91
95
92
96
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
95
99
96
100
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.
97
101
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.
99
103
100
104
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.
101
105
@@ -121,10 +125,12 @@ Now you have the **MXChip IoT DevKit** DCM and its associated interfaces, you ca
121
125
122
126
1. Choose **ANSI C** as your language.
123
127
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
-
126
128
1. Choose **Via DPS (Device Provisioning Service) symmetric key** as the connection method.
127
129
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
+
128
134
1. VS Code opens a new window with generated device code stub files in the `devkit_device` folder.
@@ -133,35 +139,37 @@ Now you have the **MXChip IoT DevKit** DCM and its associated interfaces, you ca
133
139
134
140
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.
135
141
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:
137
143
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
142
147
```
143
148
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:
145
150
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
149
155
```
150
156
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:
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"
156
164
```
157
165
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:
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.
0 commit comments