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.
Note: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.
Change the platform in CMakeLists.txt
to FreeRTOS and enable the code extraction feature:
set(BUILD_TYPE "release")
set(PLATFORM "freertos")
set(EXTRACT_SRC ON)
set(FEATURE_AT_TCP_ENABLED OFF)
Run the following command on Linux:
mkdir build
cd build
cmake ..
You can find the relevant code files in output/qcloud_iot_c_sdk
with the following directory hierarchy:
qcloud_iot_c_sdk
├── include
│ ├── config.h
│ ├── exports
├── platform
└── sdk_src
└── internal_inc
Note:
include
directory: contains the SDK APIs and variable parameters, whereconfig.h
is the compilation macros generated according to the compilation options. For more information, please see API and Variable Parameter Description.platform
directory: 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_src
directory: contains the SDK core logic and protocol-related code, which generally don't need to be modified, whereinternal_inc
is the header file used internally by the SDK.
- You can copy
qcloud_iot_c_sdk
to 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_sdk
directory extracted above to components/qcloud_iot
.components/qcloud_iot
, create a compilation configuration file component.mk
with the following content:#
# 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
At this point, you can compile qcloud_iot_c_sdk
as a component and then call the IoT Hub C-SDK APIs in your code to connect devices and send/receive messages.
Was this page helpful?