Note:The Ubuntu version used for demonstration in this document is v16.04.
Install the necessary software
The SDK requires CMake v3.5 or above. The CMake version installed by default is low. If compilation fails, download and install the specific version of CMake as instructed in Installation Instructions.
$ sudo apt-get install -y build-essential make git gcc cmake
Modify the configuration
Modify the CMakeLists.txt
file in the root directory of the SDK and make sure that the following options exist (with a key-authenticated device as example):
set(BUILD_TYPE "release")
set(COMPILE_TOOLS "gcc")
set(PLATFORM "linux")
set(FEATURE_MQTT_COMM_ENABLED ON)
set(FEATURE_AUTH_MODE "KEY")
set(FEATURE_AUTH_WITH_NOTLS OFF)
set(FEATURE_DEBUG_DEV_INFO_USED OFF)
Run the script for compilation
Below is a complete compilation library and demo:
./cmake_build.sh
The output library files, header files, and samples are in the output/release
folder.
After the complete compilation, if you only need to compile the demo, then run the following code:
./cmake_build.sh samples
Enter the device information
Enter the information of the device created on the IoT Hub platform (with a key-authenticated device as example) in device_info.json
in the root directory of the SDK. Below is the sample code:
"auth_mode":"KEY",
"productId":"S3EUVBQAZW",
"deviceName":"test_device",
"key_deviceinfo":{
"deviceSecret":"vX6PQqazsGsMyf5SMfs6OA6y"
}
Run the demo
The demo output is in the output/release/bin
folder. For example, to run the data_template_sample
demo, enter ./output/release/bin/data_template_sample
.
Run Visual Studio, select Open a local folder, and select the downloaded SDK for C directory.
Enter the information of the device created in the IoT Hub console (with a key-authenticated device as example) in device_info.json
. Below is the sample code:
"auth_mode":"KEY",
"productId":"S3EUVBQAZW",
"deviceName":"test_device",
"key_deviceinfo":{
"deviceSecret":"vX6PQqazsGsMyf5SMfs6OA6y"
}
Double-click CMakeLists.txt
in the root directory and make sure that the platform is set to Windows and the compilation tool is set to MSVC in the compilation toolchain.
# Compilation toolchain
#set(COMPILE_TOOLS "gcc")
#set(PLATFORM "linux")
set(COMPILE_TOOLS "MSVC")
set(PLATFORM "windows")
Visual Studio will automatically build the CMake cache. Just wait for the build to complete.
After the cache is generated, select Build > Build All.
Select the corresponding demo for running, which should correspond to the user information.
Was this page helpful?