Windows Build Instructions

Windows Build Instructions

Building and Running with Visual Studio 2019

  • Download and install Visual Studio 2019. Must add “Desktop development with c++” workload inside Visual
    Studio 19 for developing a desktop application
  • Download and install CMake.
    Ensure to add CMake to the system path. Suggesting, installing CMake under the path “C:\ProgramData\Tools\CMake”.
  • If you wish to build with the Paho MQTT client instead of Azure SDK, Select File->Settings->Build,
    Execution, Deployment->CMake and enter -DIOTC_USE_PAHO=ON in the “CMake options” entry box.
  • Download and extract Vcpkg. Must download the latest package and Extract it at the same path where the
    CMake is installed eg. “C:\ProgramData\Tools\vcpkg-2022.04.12”
  • Run PowerShell and execute (use x86 instead of x64 if on a 32-bit machine:
cd vcpkg install directory
  .\bootstrap-vcpkg.bat
  .\vcpkg.exe integrate install
  .\vcpkg.exe install curl:x64-windows
  .\vcpkg.exe install openssl:x64-windows 
  exit
  • By exiting the PowerShell we ensure that we pick up the “integrate install” environment.
  • Run a new PowerShell or use the developer console in Visual Studio. If running PowerShell ensure to change the
    directory to where this repo is extracted or cloned.
  • This sample provides sample application code that can be configured at build time with the following parameters
    in config/app_config.h:
  • Basic Device Parameters:
    • CPID:  Settings->Key Vault in IoTConnect Web UI
    • Environment:  Settings->Key Vault in IoTConnect Web UI
    • IOTCONNECT_DISCOVERY_HOSTNAME: *Settings->Discovery Url
    • Unique Device ID (DUID): The device’s Unique ID in IoTConnect Web UI of your device.
  • Authentication types and relevant parameters depending on the type (IOTCONNECT_AUTH_TYPE):
    • Token (IOTC_AT_TOKEN): This low-security method requires no parameters. Any device with this authentication method can connect to IoTConnect given the above Basic Device Parameters.
    • Symmetric Key (IOTC_AT_SYMMETRIC_KEY): Symmetric Key authentication requires that IOTCONNECT_SYMMETRIC_KEY is set to either Primary or Secondary key.
    • x509 (IOTC_AT_X509): For devices with CA Certificate or Self-signed Certificate authentication types You will be having cert_your_deviceid.crt(device certificate) & pk_your_deviceid.pem)(device key) from that, you need to convert .crt to .pem To do so You must have OpenSSL installed in your system. Open the folder in cmd where you have a certificate and private key & execute the below command.

       openssl x509 -in cert_your_deviceid.crt -out client-crt.pem

      Store the device certificate and private key at the certs(\iotc-generic-c-sdk_2.1\samples\basic-sample\certs) directory as client-crt.pem and client-kep.pem respectively before building. For AWS replace the server.pem with your root-CA.pem.

    • TPM (IOTC_AT_TPM):If IOTCONNECT_DUID is blank, the TPM Registration ID will be obtained from TPM and it will be used in place of IOTCONNECT_DUIDIOTCONNECT_SCOPE_ID must be set to the Scope ID provided in your Settings->Key Vault section under the DPS tab as Scope ID for TPM Devices.
cd samples/basic-sample
  mkdir build
  cd build
  cmake .. -DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake
  cmake --build . --target basic-sample
  .\Debug\basic-sample.exe
  • If you wish to build with the Paho MQTT client, append -DIOTC_USE_PAHO=ON to the cmake.. command line.

Building and Running with MSYS2 and CMake Command Line

The MSYS2 setup is less complex and faster, however, the Azure IoT C SDK integration is not supported with MSYS2. You must use the Paho MQTT Client integration.

  • Download and Install MSYS2
  • From MSYS2 bash shell, execute:
pacman --sync --noconfirm base-devel gcc cmake openssl-devel libcurl-devel
  cd <this repo sources>/samples/basic-sample
  mkdir build
  cd build
  cmake .. -DIOTC_USE_PAHO=ON
  cmake --build . --target basic-sample
  ./basic-sample.exe

Building and Running with CLion in Visual Studio Environment

  • In CLion, open the basic-sample project from the samples directory of this repo
  • In the top right of  the IDE next to the hammer icon, select basic-sample
  • Select File->Settings->Build,Execution,Deployment->CMake and enter
    -DCMAKE_TOOLCHAIN_FILE=<vcpkg install directory>/scripts/buildsystems/vcpkg.cmake
  • If you wish to build with the Paho MQTT client instead of Azure SDK, Select File->Settings->Build, Execution, Deployment->CMake, and append -DIOTC_USE_PAHO=ON in the “CMake options” entry box.
  • Click the build or execute icon.

Git Setup

If you wish to use the git clone instead of the source packages from this repo Releases page:

  • Install git for Windows with default setup options, or use MSYS2 git (see above) with Pacman in the bash shell
  • Run:
git clone <this-repo>
  cd iotc-generic-c-sdk-2.1
  git submodule update --init --recursive
  git update-index --assume-unchanged samples/basic-sample/config/app_config.h

The submodule command will pull the dependency submodules and the update-index command will ensure that you don’t accidentally check your device credentials or account information in app_config.h.