All Products
Search
Document Center

IoT Platform:Connect a device to IoT Platform

Last Updated:Jun 10, 2026

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

  1. Download the C SDK for devices: C SDK 4.x.

  2. 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.

    View instance endpoints.

    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

    device1

    device_secret

    8c684ef***

  3. On the Linux virtual machine, install the required software.

    sudo apt-get install -y build-essential make gcc
  4. Upload the modified LinkSDK directory to your Linux virtual machine.

  5. In the SDK root directory /LinkSDK, run the make command to compile the sample program.

    make clean
    make

    The compiled binary data-model-basic-demo is in ./output.

  6. Run the sample program.

    ./output/data-model-basic-demo

    Expected output:

    Successful execution

  7. In the IoT Platform console, go to the Public Instance page. Verify the device status.

    • Choose Device Management > Devices. If the device status is Online, the device is connected to IoT Platform.Device online status

    • 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.

      TSL data - street lamp

What to do next

You can now subscribe to device messages from the server.