You can run device SDK for C-based code on Linux devices and connect these devices to IoT Platform by using Message Queuing Telemetry Transport (MQTT). This topic describes how to provision and connect a device to IoT Platform. It uses sample code that is written based on device SDK for C as an example. You can run the sample code on Ubuntu x86_64.

Background information

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

Create a product and add 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).
    Authentication Mode Select Device Secret.
  3. In the left-side navigation pane, click Devices. On the Devices page, click Add Device to add a device in the product.
    After the device is added, obtain the certificate information of the device. The certificate information includes the ProductKey, DeviceName, and DeviceSecret parameters.

Create a TSL model

IoT Platform provides the C SDK Demo package. You can obtain a sample Thing Specification Language (TSL) model that is included in a JSON file of the package. Import the JSON file and apply the TSL model to the device.

  1. Edit the JSON file.
    1. Download the C SDK Demo package.
    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.
      Specify ProductKey
  2. On the Products page of the IoT Platform console, find the new device and click View.
  3. On the Define Feature tab of the Product Details page, choose Edit Draft > 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 click OK.
    Import TSL
    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 C SDK Demo package

In an Integrated Development Environment (IDE), import the C SDK Demo package as a project and replace the information in the following configuration file with the information of your device.

  1. In the HAL_OS_linux.c file of the wrappers/os/ubuntu directory, specify the certificate information of your device.
  2. Compile the project In the working directory of the project, run the make reconfig command, enter 3, and then run the make command.
    make reconfig
  3. Run the project
    In the working directory of the project, run the ./src/dev_model/examples/linkkit_example_solo project. The following figure shows the result.Run the project
    After you run the project, view the status of the device and the TSL model that the device reports on the Product Details of the IoT Platform console.