platform | device | language |
---|---|---|
linux |
vho1-x |
c |
- Introduction
- Step 1: Prerequisites
- Step 2: Prepare your Device
- Step 3: Setup the development environment
- Step 4: Build and Run the Sample
About this document
This document describes how to connect VHo1-X device running Linux with Azure IoT SDK. This multi-step process includes:
- Configuring Azure IoT Hub
- Registering your IoT device
- Build and deploy Azure IoT SDK on device
You should have the following items ready before beginning the process:
- Computer with a Git client installed so that you can access the azure-iot-sdks code on GitHub.
- VHo1-X Device.
- Ubuntu x86 machine (for cross compiling)
- Setup your IoT hub
- Provision your device and get its credentials
- Connect the VHo1-X using the twisted pair for SDK download and data transfer.
This section shows you how to set up a development environment for the Azure IoT device SDK for C on VHo1-X.
-
Download curl-7.49.1.tar.gz and openssl-1.0.2h.tar.gz for cross compiling.
-
Download the Microsoft Azure IoT Device SDK by issuing following command:
git clone --recursive https://github.com/Azure/azure-iot-sdks.git
-
Navigate to the folder c/build_all/linux in your local copy of the repository.
-
Switch to the SDK directory tree.
cd ~/azure-iot-sdks/c/build_all/linux
-
Using the text editor of your choice, create a new file in this directory and call it toolchain-rpi.cmake and add following lines to it:
INCLUDE(CMakeForceCompiler) SET(CMAKE_SYSTEM_NAME Linux) # this one is important SET(CMAKE_SYSTEM_VERSION 1) # this one not so much # this is the location of the arm toolchain targeting the beaglebone SET(CMAKE_C_COMPILER ~/cross_tools/linux-devkit/bin/arm-arago-linux-gnueabi-gcc) # this is the file system root of the target SET(CMAKE_FIND_ROOT_PATH ~/cross_tools/linux-devkit/) # search for programs in the build host directories SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # for libraries and headers in the target directories SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
-
Save the toolchain file. Your cross compilation environment is now complete.
-
Edit the following file using any text editor of your choice: azure-iot-sdks/c/iothub_client/samples/iothub_client_sample_mqtt/iothub_client_sample_mqtt.c
-
Find the following place holder for IoT connection string:
static const char* connectionString = "[device connection string]";
-
Replace the above placeholder with device connection string you obtained in Step 1 and save the changes.
-
Add certificates define.
const char certificates[];
if (IoTHubClient_LL_SetOption(iotHubClientHandle, "TrustedCerts", certificates) != IOTHUB_CLIENT_OK) { printf("failure to set option \"TrustedCerts\"\r\n"); }
-
Conditional compile on the above code to pass certificate.
-
Because cross compiling toolchain gcc version is 4.5.3, /c/serializer/inc/agenttypesystem.h code must be modified to pass compiling.
Del Line33:typedef struct AGENT_DATA_TYPE_TAG AGENT_DATA_TYPE; Del Line540:AGENT_DATA_TYPE* value; Add Line540:struct AGENT_DATA_TYPE_TAG * value;
-
Build the SDK using following command.
sudo ./azure-iot-sdks/c/build_all/linux/build.sh --toolchain-file toolchain-rpi.cmake --no-amqp --no-http --skip-unittests -cl -DMBED_BUILD_TIMESTAMP | tee LogFile.txt
- Transfer following libraries to target board directory /usr/lib.
libcrypto.so.1.0.0 libssl.so.1.0.0 libcurl.so.4.4.0
- Transfer the sample executable iothub_client_sample_mqtt to target board directory /usr/local/bin.
***Note:***Because sample code is compiled with 'TrustedCerts', there is no need to install certificates.
-
Before run the sample ,the device must clock calibrating ,use following command to calibrate.
ntpdate [NtpServer]
/usr/local/bin/iothub_client_sample_mqtt
- See Manage IoT Hub to learn how to observe the messages IoT Hub receives from the application.
- See Manage IoT Hub to learn how to send cloud-to-device messages to the application.