Tutorial to build the Aliyun IoT SDK for C.
ALIYUN-IOT-SDK-C
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
- Sign in to Aliyun IoT Cloud. If you do not have an account, please register a new one.
Create Product
In the left navigation pane, expand Devices and then choose Product.
create_product_01
On the Products page, choose Create Product and fill in the necessary information then choose OK.
create_product_02
Finish creating the Product.
create_product_03
Create Device
In the left navigation pane, expand Devices and then choose Device.
create_device_01
On the Devices page, choose Add Device and fill in the necessary information then choose OK.
create_device_02
Finish creating the Device.
create_device_03
Create Topic
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.
create_topic_01
On the Product Details page, choose Notifications > Create Topic Category.
create_topic_02
On the Create Topic Category page, fill in the necessary information then choose OK.
create_topic_03
Finish creating the Topic.
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
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.
copy_device_identification_01
On the Device Information tab, you can find and copy the device identification ProductKey, DeviceName and DeviceSecret.
copy_device_identification_02
View Device Log
You can view the following device log after section Execute the SDK
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.
view_device_log_01
On the Device Log tab, you can view all device log in subtabs of Device Actitivity Analysis, Upstream Analysis and Downstream Analysis.
view_device_log_02
view_device_log_03
view_device_log_04
Host (x86_64-linux)
Cross-compiling the SDK
Setup the Environment
- Setup a network connection to allow host able to access the network.
- Install GNU cross-toolchain provide by MOXA.
- Install following package from package manager.
1 cmake git rsync tree vim
Build the SDK
- Clone repository of MOXA cloud connectivity tool from github.
1 user@Linux:~$ git clone https://github.com/MoxaCorp/ioThinx-4530-aliyun-iot.git
- Setup dependencies and SDK to output directory.
1 user@Linux:~$ cd aliyun
1 user@Linux:~/aliyun$ ./setup.sh
- For more setup.sh options.
1 user@Linux:~/aliyun$ ./setup.sh --help
3 Usage: ./setup.sh [options]
6 -git Git repository of SDK.
7 Default: https://github.com/aliyun/iotkit-embedded.git
10 Default: RELEASED_V2.03
12 --toolchain GNU cross-toolchain directory.
13 Default: /usr/local/arm-linux-gnueabihf
15 --help Display this help and exit.
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
- Add the device identification ProductKey, DeviceName and DeviceSecret to SDK sample code such as example mqtt-example.c. [Copy Device Identification]
1 user@Linux:~/aliyun$ 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"
- Build the whole SDK.
1 user@Linux:~/aliyun$ ./build.sh
- All compiled SDK program can be found in the following directory, including example mqtt-example.
1 user@Linux:~/aliyun$ tree output/sdk_aliyun/output/release/bin
2 output/sdk_aliyun/output/release/bin
6 ├── mqtt_multi_thread-example
- You can also reference to the MOXA sample code with ioThinx I/O library moxa_sample_mqtt.c in the following directory.
1 user@Linux:~/aliyun$ tree sample
- The compiled MOXA program moxa_sample_mqtt will be generated after the whole SDK is built.
- Note
1 In general, the setup.sh only needs to be executed once.
2 The build.sh needs to be executed after any code change of the SDK.
Target (arm-linux)
Executing the SDK program
Setup the Environment
- Setup a network connection to allow target able to access the network.
- Install following package from package manager.
- Copy compiled SDK program from host to target.
Execute the SDK
- Execute SDK program that cross-compiled by host.
1 moxa@Moxa:~$ sudo ./mqtt-example
- View device log on cloud.
Reference
[1] https://github.com/aliyun/iotkit-embedded
[2] https://www.alibabacloud.com/help/product/30520.htm