Alibaba Cloud IoT Platform provides device SDKs that allow devices to connect to the
platform. This topic describes how to enable communication between a device and IoT
Platform by using the data_model_basic_demo
sample code. A street lamp is developed in this example.
Background information
- In this topic, Link SDK for C is used on the Linux operating system. We recommend
that you use 64-bit Ubuntu 16.04 to compile the SDK.
- The following software is required for SDK development and compilation:
make (version 4.1 or later) and gcc (version 5.4.0 or later)
Run the following command to install the software:
sudo apt-get install -y build-essential make gcc
Procedure
- Obtain Link SDK for C :C SDK 4.x. .
- Decompress the downloaded Link SDK for C and modify the device certificate in the
SDK.
Click the
data_model_basic_demo.c link to download the
data_model_basic_demo.c file, replace the
data_model_basic_demo.c file in the path
\LinkSDK\demos, and configure the following parameters.
char *product_key = "a2***";
char *device_name = "device1";
char *device_secret = "8c684ef***";
...
...
char *mqtt_host = "a2***.iot-as-mqtt.cn-shanghai.aliyuncs.com";
Parameter |
Example |
Description |
mqtt_host |
- Public instance of the new version: iot-cn-***.mqtt.iothub.aliyuncs.com
- Public instance of the old version: a2***.iot-as-mqtt.cn-shanghai.aliyuncs.com
|
The MQTT endpoint.
- Endpoint of a public instance of the new version: On the Instance Details page, click View Development Configurations in the upper-right corner. In the Development Configurations panel, view the endpoint.
- Endpoint of a public instance of the old version: The endpoint is in the format of
${YourProductKey}.iot-as-mqtt.${YourRegionId}.aliyuncs.com .
For more information, see View the endpoint of an instance.
|
product_key |
a2*** |
The device certificate used for authentication. This certificate is saved on premises
after you add the device.
You can also view the device certificate on the Device Details page in the IoT Platform console. For more information, see Obtain device authentication information.
|
device_name |
device1 |
device_secret |
8c684ef*** |
- Log on to the Linux virtual machine and run the following command to install the required
software:
sudo apt-get install -y build-essential make gcc
- Upload the LinkSDK file that is modified in Step 2 to the development environment.
- Go to the SDK root directory /LinkSDK and run the
make
command to compile the sample code: make clean
make
The generated data-model-basic-demo
file is stored in the ./output directory.
- Run the sample code.
./output/data-model-basic-demo
The following figure shows a sample success response:

- Log on to the IoT Platform console and go to the Public Instance page to view the online status and running status of your device.