How to build Aliyun IoT SDK for C

Tutorial to build the Aliyun IoT SDK for C.

ioThinx-4530-aliyun-iot

Table of Contents

Cloud: Create device instance for connecting by SDK program

Host: Cross-compiling the SDK

Target: Executing the SDK program

Cloud (Aliyun)

Create device instance for connecting by SDK program

Sign in to Cloud

Create Product

  1. In the left navigation pane, expand Devices and then choose Product.

    aliyun_create_product_01.png
    create_product_01
  2. On the Products page, choose Create Product and fill in the necessary information then choose OK.

    aliyun_create_product_02.png
    create_product_02
  3. Finish creating the Product.

    aliyun_create_product_03.png
    create_product_03

Create Device

  1. In the left navigation pane, expand Devices and then choose Device.

    aliyun_create_device_01.png
    create_device_01
  2. On the Devices page, choose Add Device and fill in the necessary information then choose OK.

    aliyun_create_device_02.png
    create_device_02
  3. Finish creating the Device.

    aliyun_create_device_03.png
    create_device_03

Create Topic

  1. In the left navigation pane, expand Devices and then choose Product. On the Products page, search for the [Product you create before] then choose View.

    aliyun_create_topic_01.png
    create_topic_01
  2. On the Product Details page, choose Notifications > Create Topic Category.

    aliyun_create_topic_02.png
    create_topic_02
  3. On the Create Topic Category page, fill in the necessary information then choose OK.

    aliyun_create_topic_03.png
    create_topic_03
  4. Finish creating the Topic.

    aliyun_create_topic_04.png
    create_topic_04

Copy Device Identification

Device Identification is the key to build connection between physical and virtual device on cloud

You will need this infomation in the section Build the SDK

  1. In the left navigation pane, expand Devices and then choose Device. On the Devices page, search for the [Device you create before] then choose View.

    aliyun_copy_device_identification_01.png
    copy_device_identification_01
  2. On the Device Information tab, you can find and copy the device identification ProductKey, DeviceName and DeviceSecret.

    aliyun_copy_device_identification_02.png
    copy_device_identification_02

View Device Log

You can view the following device log after section Execute the SDK

  1. In the left navigation pane, expand Devices and then choose Product. On the Products page, search for the [Product you create before] then choose View.

    aliyun_view_device_log_01.png
    view_device_log_01
  2. On the Device Log tab, you can view all device log in subtabs of Device Actitivity Analysis, Upstream Analysis and Downstream Analysis.

    aliyun_view_device_log_02.png
    view_device_log_02
    aliyun_view_device_log_03.png
    view_device_log_03
    aliyun_view_device_log_04.png
    view_device_log_04

Host (x86_64-linux)

Cross-compiling the SDK

Setup the Environment

  1. Setup a network connection to allow host able to access the network.
  2. Install GNU cross-toolchain provide by MOXA.
  3. Install following package from package manager.
    1 cmake git rsync tree vim

Build the SDK

  1. Clone repository of MOXA cloud connectivity tool from github.
    1 user@Linux:~$ git clone https://github.com/MoxaCorp/ioThinx-4530-aliyun-iot.git
  2. Setup dependencies and SDK to output directory.
    1 user@Linux:~$ cd ioThinx-4530-aliyun-iot
    1 user@Linux:~/ioThinx-4530-aliyun-iot$ ./setup.sh
    • For more setup.sh options.
      1 user@Linux:~/ioThinx-4530-aliyun-iot$ ./setup.sh --help
      2 
      3 Usage: ./setup.sh [options]
      4 
      5 Options:
      6  -git Git repository of SDK.
      7  Default: https://github.com/aliyun/iotkit-embedded.git
      8 
      9  -ver Version of SDK.
      10  Default: RELEASED_V2.03
      11 
      12  --toolchain GNU cross-toolchain directory.
      13  Default: /usr/local/arm-linux-gnueabihf
      14 
      15  --help Display this help and exit.
      16 
      17 Examples:
      18  Default ./setup.sh
      19  Specify ./setup.sh -git https://github.com/aliyun/iotkit-embedded.git -ver RELEASED_V2.03
      20  ./setup.sh --toolchain /usr/local/arm-linux-gnueabihf
  3. Add the device identification ProductKey, DeviceName and DeviceSecret to SDK sample code such as example mqtt-example.c. [Copy Device Identification]
    1 user@Linux:~/ioThinx-4530-aliyun-iot$ vim output/sdk_aliyun/sample/mqtt/mqtt-example.c
    1 #define PRODUCT_KEY "a14qsGgMTtk"
    2 #define DEVICE_NAME "Example_Device"
    3 #define DEVICE_SECRET "CTA83oLWKq2n0YgvveFZusvVqeA0EVTq"
  4. Build the whole SDK.
    1 user@Linux:~/ioThinx-4530-aliyun-iot$ ./build.sh
    • All compiled SDK program can be found in the following directory, including example mqtt-example.
      1 user@Linux:~/ioThinx-4530-aliyun-iot$ tree output/sdk_aliyun/output/release/bin
      2 output/sdk_aliyun/output/release/bin
      3 ├── coap-example
      4 ├── http-example
      5 ├── mqtt-example
      6 ├── mqtt_multi_thread-example
      7 ├── mqtt_rrpc-example
      8 ├── ota_mqtt-example
      9 ├── sdk-testsuites
      10 └── shadow-example

Target (arm-linux)

Executing the SDK program

Setup the Environment

  1. Setup a network connection to allow target able to access the network.
  2. Install following package from package manager.
    1 tree
  3. Copy compiled SDK program from host to target.
    1 moxa@Moxa:~$ tree
    2 .
    3 └── mqtt-example

Execute the SDK

  1. Execute SDK program that cross-compiled by host.
    1 moxa@Moxa:~$ sudo ./mqtt-example
  2. View device log on cloud.

Reference

[1] https://github.com/aliyun/iotkit-embedded

[2] https://www.alibabacloud.com/help/product/30520.htm