1 How to build Aliyun IoT SDK for C {#aliyun}
3 @brief Tutorial to build the Aliyun IoT SDK for C.
5 # ioThinx-4530-aliyun-iot {#aliyun-iothinx-4530-aliyun-iot}
7 > **Table of Contents**
9 > [Cloud: Create device instance for connecting by SDK program](#aliyun-cloud-aliyun)
11 > [Host: Cross-compiling the SDK](#aliyun-host-x86_64-linux)
13 > [Target: Executing the SDK program](#aliyun-target-arm-linux)
15 ## Cloud (Aliyun) {#aliyun-cloud-aliyun}
17 > Create device instance for connecting by SDK program
19 ### Sign in to Cloud {#aliyun-sign-in-to-cloud}
21 * Sign in to [Aliyun IoT Cloud][cloud]. If you do not have an account, please register a new one.
23 ### Create Product {#aliyun-create-product}
25 1. In the left navigation pane, expand **Devices** and then choose **Product**.
27 ![create_product_01][create_product_01]
29 2. On the **Products** page, choose **Create Product** and fill in the necessary information then choose **OK**.
31 ![create_product_02][create_product_02]
33 3. Finish creating the Product.
35 ![create_product_03][create_product_03]
37 ### Create Device {#aliyun-create-device}
39 1. In the left navigation pane, expand **Devices** and then choose **Device**.
41 ![create_device_01][create_device_01]
43 2. On the **Devices** page, choose **Add Device** and fill in the necessary information then choose **OK**.
45 ![create_device_02][create_device_02]
47 3. Finish creating the Device.
49 ![create_device_03][create_device_03]
51 ### Create Topic {#aliyun-create-topic}
53 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**.
55 ![create_topic_01][create_topic_01]
57 2. On the **Product Details** page, choose **Notifications** > **Create Topic Category**.
59 ![create_topic_02][create_topic_02]
61 3. On the **Create Topic Category** page, fill in the necessary information then choose **OK**.
63 ![create_topic_03][create_topic_03]
65 4. Finish creating the Topic.
67 ![create_topic_04][create_topic_04]
69 ### Copy Device Identification {#aliyun-copy-device-identification}
71 > **Device Identification** is the key to build connection between physical and virtual device on cloud
73 > You will need this infomation in the section [Build the SDK](#aliyun-build-the-sdk)
75 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**.
77 ![copy_device_identification_01][copy_device_identification_01]
79 2. On the **Device Information** tab, you can find and copy the device identification **ProductKey**, **DeviceName** and **DeviceSecret**.
81 ![copy_device_identification_02][copy_device_identification_02]
83 ### View Device Log {#aliyun-view-device-log}
85 > You can view the following device log after section [Execute the SDK](#aliyun-execute-the-sdk)
87 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**.
89 ![view_device_log_01][view_device_log_01]
91 2. On the **Device Log** tab, you can view all device log in subtabs of **Device Actitivity Analysis**, **Upstream Analysis** and **Downstream Analysis**.
93 ![view_device_log_02][view_device_log_02]
94 ![view_device_log_03][view_device_log_03]
95 ![view_device_log_04][view_device_log_04]
97 ## Host (x86_64-linux) {#aliyun-host-x86_64-linux}
99 > Cross-compiling the SDK
101 ### Setup the Environment {#aliyun-setup-the-environment}
103 1. Setup a network connection to allow host able to access the network.
105 2. Install GNU cross-toolchain provide by MOXA.
107 3. Install following package from package manager.
109 cmake git rsync tree vim
112 ### Build the SDK {#aliyun-build-the-sdk}
114 1. Clone repository of MOXA cloud connectivity tool from github.
116 user@Linux:~$ git clone https://github.com/MoxaCorp/ioThinx-4530-aliyun-iot.git
119 2. Setup dependencies and SDK to output directory.
121 user@Linux:~$ cd ioThinx-4530-aliyun-iot
124 user@Linux:~/ioThinx-4530-aliyun-iot$ ./setup.sh
126 * For more setup.sh options.
128 user@Linux:~/ioThinx-4530-aliyun-iot$ ./setup.sh --help
130 Usage: ./setup.sh [options]
133 -git Git repository of SDK.
134 Default: https://github.com/aliyun/iotkit-embedded.git
137 Default: RELEASED_V2.03
139 --toolchain GNU cross-toolchain directory.
140 Default: /usr/local/arm-linux-gnueabihf
142 --help Display this help and exit.
146 Specify ./setup.sh -git https://github.com/aliyun/iotkit-embedded.git -ver RELEASED_V2.03
147 ./setup.sh --toolchain /usr/local/arm-linux-gnueabihf
150 3. Add the device identification **ProductKey**, **DeviceName** and **DeviceSecret** to SDK sample code such as example **mqtt-example.c**. [[Copy Device Identification](#aliyun-copy-device-identification)]
152 user@Linux:~/ioThinx-4530-aliyun-iot$ vim output/sdk_aliyun/sample/mqtt/mqtt-example.c
155 #define PRODUCT_KEY "a14qsGgMTtk"
156 #define DEVICE_NAME "Example_Device"
157 #define DEVICE_SECRET "CTA83oLWKq2n0YgvveFZusvVqeA0EVTq"
160 4. Build the whole SDK.
162 user@Linux:~/ioThinx-4530-aliyun-iot$ ./build.sh
164 * All compiled SDK program can be found in the following directory, including example **mqtt-example**.
166 user@Linux:~/ioThinx-4530-aliyun-iot$ tree output/sdk_aliyun/output/release/bin
167 output/sdk_aliyun/output/release/bin
171 ├── mqtt_multi_thread-example
172 ├── mqtt_rrpc-example
178 * You can also reference to the MOXA sample code with ioThinx I/O library **moxa_sample_mqtt.c** in the following directory. This sample code can be executed directly on the target device with module 45MR-2606 located in slot 1.
180 user@Linux:~/ioThinx-4530-aliyun-iot$ tree sample
183 │ └── moxa_sample_mqtt
185 └── moxa_sample_mqtt.c
187 * The compiled MOXA program **moxa_sample_mqtt** will be generated after the whole SDK is built.
191 In general, the setup.sh only needs to be executed once.
192 The build.sh needs to be executed after any code change of the SDK.
195 ## Target (arm-linux) {#aliyun-target-arm-linux}
197 > Executing the SDK program
199 ### Setup the Environment {#aliyun-setup-the-environment-1}
201 1. Setup a network connection to allow target able to access the network.
203 2. Install following package from package manager.
208 3. Copy compiled SDK program from host to target.
215 ### Execute the SDK {#aliyun-execute-the-sdk}
217 1. Execute SDK program that cross-compiled by host.
219 moxa@Moxa:~$ sudo ./mqtt-example
222 2. [View device log on cloud](#aliyun-view-device-log).
224 ## Reference {#aliyun-reference}
226 [1] [https://github.com/aliyun/iotkit-embedded][Reference_01]
228 [2] [https://www.alibabacloud.com/help/product/30520.htm][Reference_02]
230 [comment]: # (Images)
231 [create_product_01]: readme/aliyun_create_product_01.png
232 [create_product_02]: readme/aliyun_create_product_02.png
233 [create_product_03]: readme/aliyun_create_product_03.png
235 [create_device_01]: readme/aliyun_create_device_01.png
236 [create_device_02]: readme/aliyun_create_device_02.png
237 [create_device_03]: readme/aliyun_create_device_03.png
239 [create_topic_01]: readme/aliyun_create_topic_01.png
240 [create_topic_02]: readme/aliyun_create_topic_02.png
241 [create_topic_03]: readme/aliyun_create_topic_03.png
242 [create_topic_04]: readme/aliyun_create_topic_04.png
244 [copy_device_identification_01]: readme/aliyun_copy_device_identification_01.png
245 [copy_device_identification_02]: readme/aliyun_copy_device_identification_02.png
247 [view_device_log_01]: readme/aliyun_view_device_log_01.png
248 [view_device_log_02]: readme/aliyun_view_device_log_02.png
249 [view_device_log_03]: readme/aliyun_view_device_log_03.png
250 [view_device_log_04]: readme/aliyun_view_device_log_04.png
253 [cloud]: https://iot.console.aliyun.com
254 [Reference_01]: https://github.com/aliyun/iotkit-embedded
255 [Reference_02]: https://www.alibabacloud.com/help/product/30520.htm