You can directly compile and run the demo in the device SDK for C on a Linux device to connect to IoT Platform by using Message Queuing Telemetry Transport (MQTT). This article describes how to configure and connect a Linux device to IoT Platform. In the following example, the demo in the device SDK for C is compiled on a device that runs the Ubuntu x86_64 operating system.

Background information

For more information about the device SDK for C, see Overview.

Create a product and a device

  1. Log on to the IoT Platform console.
  2. On the Overview page, find the instance that you want to manage and click the instance name to go to the Instance Details page.
    Important Enterprise Edition instances are available in the China (Shanghai) and Japan (Tokyo) regions. If the Enterprise Edition instances are unavailable in the region that you select, skip this step.
    Overview
  3. In the left-side navigation pane, choose Devices > Products. On the Products page, click Create Product to create a product.
    Parameter Description
    Product Name The name of the product.
    Node Type Select Directly Connected Device.
    Network Connection Method Select Wi-Fi.
    Data Type Select ICA Standard Data Format (Alink JSON).
    Authorization Mode Select Device Secret.
  4. In the left-side navigation pane, choose Devices > Devices. On the Devices page, click Add Device to add a device to the product.
    After the device is added, obtain the certificate information of the device. The certificate information includes the ProductKey, DeviceName, and DeviceSecret.

Create a TSL model

In the package of the device SDK for C provided by IoT Platform, you can obtain a JSON file that contains a complete sample Thing Specification Language (TSL) model. In the following example, the JSON file is imported to apply the TSL model to the product.

  1. Modify the JSON file.
    1. Download the device SDK for C V3.2 package. For more information, see Device SDK for C V3.2.
    2. Decompress the package and open the model_for_examples.json file in the src/dev_model/examples directory.
    3. Specify the ProductKey that you obtained from IoT Platform for the productKey parameter in the JSON file. Then, save the file.
      Modify the productKey parameter of the TSL model
  2. On the Products page in the IoT Platform console, find the new device and click View.
  3. On the Define Feature tab of the Product Details page, click Edit Draft and then Import.
  4. In the Import TSL dialog box, click the Import TSL tab, upload the JSON file that you modified in the preceding step, and then click OK.
    After the file is imported, all features that are defined in the JSON file are displayed on the Edit Draft page.
  5. Click Release online to publish the TSL model.

Configure the SDK demo

Copy the package of the device SDK for C to the Linux device. Decompress the package and modify the device information in a configuration file.

  1. In the wrappers/os/ubuntu directory, specify the certificate information of your device in the HAL_OS_linux.c file.
    Modify device authentication information
  2. Compile the SDK demo. In the root directory of the SDK demo, run the make reconfig command, enter 3, and then run the make command.
    make reconfig
  3. Run the SDK demo.
    In the root directory of the SDK demo, run the ./output/release/bin/linkkit-example-solo command. The following figure shows the result. Run the device SDK for C
    After you run the SDK demo, view the status of the device and the TSL model that the device reports on the Product Details of the IoT Platform console.