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.
Create a product and add a device
- Log on to the IoT Platform console.
- In the left-side navigation pane, choose Create Product to create a product.. On the Products page, click
Parameter Description Product Name The name of the product. [DO NOT TRANSLATE] [DO NOT TRANSLATE] 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.
- 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.
- Edit the JSON file.
- Download the C SDK Demo package.
- Decompress the package, and open the model_for_examples.json file in the src/dev_model/examples directory.
- Specify the value of the ProductKey that you obtain from IoT Platform for the productKey parameter in the JSON file. Then, save the file.
- On the Products page of the IoT Platform console, find the new device and click View.
- On the Define Feature tab of the Product Details page, choose .
- 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.After the file is imported, all features that are defined in the JSON file are displayed on the Edit Draft page.
- 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.
- In the HAL_OS_linux.c file of the wrappers/os/ubuntu directory, specify the certificate information of your device.
- Compile the project In the working directory of the project, run the make reconfig command, enter 3, and then run the make command.
- Run the projectIn the working directory of the project, run the ./src/dev_model/examples/linkkit_example_solo project. The following figure shows the result.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.