Skip to content

Latest commit

 

History

History
163 lines (110 loc) · 7.1 KB

mlinux-multiconnect-conduit-c.md

File metadata and controls

163 lines (110 loc) · 7.1 KB
platform device language
mlinux
multiconnect conduit
c

Run a simple C sample on MultiConnect Conduit running mLinux


Table of Contents

Introduction

About this document

This document describes how to connect MultiConnect Conduit device running mLinux 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

Step 1: Prerequisites

You should have the following items ready before beginning the process:

Step 2: Prepare your Device

Follow the appropriate Getting Started guide for your Conduit to connect to the same network as your host PC

Step 3: Build and Run the sample

3.1 Build SDK and sample

  • If you have not already done so, install the mLinux C/C++ Toolchain

  • From a terminal on the host, load the cross compilation environment using:

    $ source /<path to sdk>/environment-setup-arm926ejste-mlinux-linux-gnueabi
    

    By default this would be::

    $ source /opt/mlinux/<version>/environment-setup-arm926ejste-mlinux-linux-gnueabi
    
  • Download the Microsoft Azure IoT Device SDK for C to the board by issuing the following command on the host

    git clone --recursive https://github.com/Azure/azure-iot-sdk-c.git
    
  • The MultiConnect Conduit supports AMQP, HTTP and MQTT. Edit the example file for the protocol(s) you wish to use using any text editor of your choice:

    • AMQP

      azure-iot-sdk-c/iothub_client/samples/iothub_client_sample_amqp/iothub_client_sample_amqp.c
      
    • HTTP

      azure-iot-sdk-c/iothub_client/samples/iothub_client_sample_amqp/iothub_client_sample_http.c
      
    • MQTT

      azure-iot-sdk-c/iothub_client/samples/iothub_client_sample_amqp/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.

  • Create a new file "toolchain.cmake" in the azure-iot-sdk-c directory and enter the text

    INCLUDE(CMakeForceCompiler)
    
    SET(CMAKE_SYSTEM_NAME Linux)
    SET(CMAKE_SYSTEM_PROCESSOR ARM)
    
    SET(CMAKE_SYSTEM_VERSION 1)
    SET(CROSS_COMPILE arm-mlinux-linux-eabi-)
    
    SET(CMAKE_FIND_ROOT_PATH $ENV{OECORE_TARGET_SYSROOT})
    SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    
  • Build the SDK using following command.

    ./build_all/linux/build.sh --toolchain-file toolchain.cmake
    
  • Transfer the compiled example(s) to your MultiConnect Conduit:

    scp ./cmake/iotsdk_linux/iothub_client/samples/iothub_client_sample_amqp/iothub_client_sample_amqp admin@<MultiConnect Conduit IP address>:~/
    scp ./cmake/iotsdk_linux/iothub_client/samples/iothub_client_sample_http/iothub_client_sample_http admin@<MultiConnect Conduit IP address>:~/
    scp ./cmake/iotsdk_linux/iothub_client/samples/iothub_client_sample_mqtt/iothub_client_sample_mqtt admin@<MultiConnect Conduit IP address>:~/
    

3.2 Send Device Events to IoT Hub:

  • Open a terminal connection to your MultiConnect Conduit over ssh or microUSB

  • Run the sample by issuing the command for the protocol you wish to run:

    ~/iothub_client_sample_amqp
    ~/iothub_client_sample_http
    ~/iothub_client_sample_mqtt
    
  • See Manage IoT Hub to learn how to observe the messages IoT Hub receives from the application.

3.3 Receive messages from IoT Hub

  • See Manage IoT Hub to learn how to send cloud-to-device messages to the application.

Tips

  • If you just want to build the serializer samples, run the following commands:

    cd ./c/serializer/build/linux
    make -f makefile.linux all
    

Next Steps

You have now learned how to run a sample application that collects sensor data and sends it to your IoT hub. To explore how to store, analyze and visualize the data from this application in Azure using a variety of different services, please click on the following lessons: