Connect a device to IoT Platform
Use the data_model_basic_demo sample program to simulate a street lamp device and connect it to IoT Platform through the C SDK.
Important notes
The steps in this topic are performed by a regular user. If you encounter an operation that requires administrative permission, run the command with sudo.
Prepare the development environment
-
The device-side C SDK runs on Linux. Compile it in a 64-bit Ubuntu 16.04 environment.
-
Required software:
make 4.1 or later, gcc 5.4.0 or later.
Install command:
sudo apt-get install -y build-essential make gcc
Procedure
-
Download the C SDK for devices.
-
Log on to the IoT Platform console.
-
In the upper-left corner of the console, select the region where your instance is located. On the Instance Overview tab, click Public Instance.
-
In the navigation pane on the left, click Documents & Tools. In the Device SDK section, under Link SDK, click Customize SDK.
-
Customize and download the SDK.
Under Advanced Capabilities, select Thing Specification Language model, keep other defaults, and click Start Generation to download the C SDK ZIP file.

-
-
Unzip the C SDK file and modify the device certificate information.
Download data_model_basic_demo.c and use it to replace the file in
\LinkSDK\demos. Update 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
-
New public instances:
iot-cn-***.mqtt.iothub.aliyuncs.com -
Old public instances:
a2***.iot-as-mqtt.cn-shanghai.aliyuncs.com
The MQTT ingest endpoint for the device.
-
New public instances: On the Instance Details page, click View Development Configurations. The endpoint appears on the Development Configurations panel.
-
Old public instances: The endpoint format is
${YourProductKey}.iot-as-mqtt.${YourRegionId}.aliyuncs.com.
product_key
a2***The device certificate saved when you added the device.
You can also view the certificate on the Device Details page in the IoT Platform console. Obtain a device certificate.
device_name
device1device_secret
8c684ef*** -
-
On the Linux virtual machine, install the required software.
sudo apt-get install -y build-essential make gcc -
Upload the modified
LinkSDKdirectory to your Linux virtual machine. -
In the SDK root directory
/LinkSDK, run themakecommand to compile the sample program.make clean makeThe compiled binary
data-model-basic-demois in./output. -
Run the sample program.
./output/data-model-basic-demoExpected output:

-
In the IoT Platform console, go to the Public Instance page. Verify the device status.
-
Choose . If the device status is Online, the device is connected to IoT Platform.

-
Click View in the Actions column. On the Device Details page, click the TSL Data tab and then Running Status.
The data_model_basic_demo.c sample reports the operating current value.

-
What to do next
You can now subscribe to device messages from the server.