This document describes how to port IoT Hub C-SDK to the FreeRTOS + lwIP platform.
As a micro-kernel system, FreeRTOS mainly provides core OS mechanisms such as task creation and scheduling and inter-task communication. Different device platforms also should be equipped with different software components before they can form a complete embedded operating platform, including C runtime libraries (such as Newlib or ARM CMSIS library) and TCP/IP network protocol stacks (such as lwIP). In addition, the compilation and development environments vary by device platform, so when porting C-SDK, you need to adapt it according to the specific conditions of different devices.
The SDK provides a reference implementation based on FreeRTOS + lwIP + Newlib in
platform/os/freertos, which has been verified and tested on Espressif's ESP8266 platform.
Because different RTOS-based platforms have different compilation methods, it is generally impossible to directly use the SDK's CMake or Make to compile. Therefore, the SDK provides the code extraction feature. It allows you to extract the relevant code into a separate folder based on your needs. The code hierarchy in the folder is concise, making it easy for you to copy and integrate it into your own development environment.
CMakeLists.txtto FreeRTOS and enable the code extraction feature:
set(BUILD_TYPE "release") set(PLATFORM "freertos") set(EXTRACT_SRC ON) set(FEATURE_AT_TCP_ENABLED OFF)
mkdir build cd build cmake ..
output/qcloud_iot_c_sdkwith the following directory hierarchy:
qcloud_iot_c_sdk ├── include │ ├── config.h │ ├── exports ├── platform └── sdk_src └── internal_inc
includedirectory: contains the SDK APIs and variable parameters, where
config.his the compilation macros generated according to the compilation options. For more information, please see API and Variable Parameter Description.
platformdirectory: contains platform-related code, which can be modified and adapted according to the specific conditions of the device. For more information on functions, please see Overview.
sdk_srcdirectory: contains the SDK core logic and protocol-related code, which generally don't need to be modified, where
internal_incis the header file used internally by the SDK.
qcloud_iot_c_sdkto the compilation and development environment of your target platform and then modify the compilation options as needed.
Build a demo project based on Espressif's ESP8266 RTOS platform in the Linux development environment.
qcloud_iot_c_sdkdirectory extracted above to
components/qcloud_iot, create a compilation configuration file
component.mkwith the following content:
At this point, you can compile
# # Component Makefile # COMPONENT_ADD_INCLUDEDIRS := \ qcloud_iot_c_sdk/include \ qcloud_iot_c_sdk/include/exports \ qcloud_iot_c_sdk/sdk_src/internal_inc COMPONENT_SRCDIRS := \ qcloud_iot_c_sdk/sdk_src \ qcloud_iot_c_sdk/platform
qcloud_iot_c_sdkas a component and then call the IoT Hub C-SDK APIs in your code to connect devices and send/receive messages.