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. 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.
  3. 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. Edit the JSON file.
    1. Download the package of the device SDK for C.
    2. Decompress the package and open the model_for_examples.json file in the src/dev_model/examples directory.
    3. Specify the value of the ProductKey that you obtain from IoT Platform for the productKey parameter in the JSON file. Then, save the file.
      Modify the productKey parameter of the TSL model
  2. Log on to the IoT Platform console. On the Products page, find the product that you created earlier and click View in the Actions column.
  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 edited in the preceding step, and then click OK.
    Import a TSL model
    After the file is imported, all features that are defined in the JSON file appear 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, 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, run the ./output/release/bin/linkkit-example-solo command. The following figure shows the result.Run the device SDK for C
    After the SDK demo is run, log on to the IoT Platform console. On the Device Details page, view the device status and the TSL data reported by the device.