IoT Hub device SDK for C relies on a secure and powerful data channel to enable IoT developers to quickly connect devices to the cloud for two-way communication.
Note:After v3.1.0, the SDK refactored and optimized the compilation environment, code, and directory structure, increasing the availability and portability.
Featuring a modular design, the SDK for C separates the core protocol service from the hardware abstraction layer and provides flexible configuration options and multiple compilation methods, making it suitable for development platforms and use environments of different devices.
glibc
or similar libraries which can provide system calls, including socket communication, SELECT sync IO, dynamic memory allocation, functions for getting time/sleeping/generating random number/printing, as well as critical data protection such as the mutex mechanism (only when multiple threads are required), only simple adaptation (e.g., changing the cross compiler settings in CMakeLists.txt
or make.settings
) is required before the SDK can be compiled and run.Newlib
and embedded TCP/IP protocol stacks like lwIP, adaptation for porting can be done easily.The directory structure and top-level documents are described as follows:
Name | Description |
---|---|
CMakeLists.txt | CMake compilation and description file |
CMakeSettings.json | CMake configuration file on Visual Studio |
cmake_build.sh | Compilation script with CMake on Linux |
make.settings | Configuration file compiled directly by Makefile on Linux |
Makefile | Direct compilation with Makefile on Linux |
device_info.json | Device information file. If DEBUG_DEV_INFO_USED = OFF , the device information will be parsed from this file |
docs | Documentation directory, i.e., the use instructions of the SDKs for different platforms |
external_libs | Third-party package components, such as Mbed TLS |
samples | Application demos |
include | External header files provided to users |
platform | Platform source code files. Currently, implementations are provided for different OS (Linux/Windows/FreeRTOS/nonOS), TLS (Mbed TLS), and AT module |
sdk_src | Core communication protocols and service code of the SDK |
tools | Compilation and code generation script tools supporting the SDK |
The SDK for C supports three compilation methods:
For more information on the compilation methods and compilation configuration options, please see Compilation Configuration Description and Compilation Environment (Linux and Windows).
The samples
directory of the SDK for C contains demos showing how to use the features. For more information on how to run the demos, please see the corresponding documents in the SDK documentation directory.
For more information on device connection to and message sending/receiving in IoT Hub over MQTT, please see Getting Started with MQTT.
Starting from SDK v3.0.3, OTA update supports checkpoint restart. When the firmware download process is interrupted due to network exceptions or other issues, the downloaded part of the firmware can be saved, so that the download can start from where interrupted instead of from the beginning when it is resumed.
After this new feature was supported, the methods of using relevant OTA APIs changed. If you have upgraded from v3.0.2 or below, you should modify your logic code; otherwise, firmware download will fail. For more information on how to modify it, please see samples/ota/ota_mqtt_sample.c
.
To improve the code readability and comply with the naming conventions, SDK v3.1.0 incorporated changes to certain variables, functions, and macro names. If you have upgraded from v3.0.3 or below, you can run the tools/update_from_old_SDK.sh
script on Linux to replace the names in your own code, and then you can use the new version of the SDK directly.
Old Name | New Name |
---|---|
QCLOUD_ERR_SUCCESS | QCLOUD_RET_SUCCESS |
QCLOUD_ERR_MQTT_RECONNECTED | QCLOUD_RET_MQTT_RECONNECTED |
QCLOUD_ERR_MQTT_MANUALLY_DISCONNECTED | QCLOUD_RET_MQTT_MANUALLY_DISCONNECTED |
QCLOUD_ERR_MQTT_CONNACK_CONNECTION_ACCEPTED | QCLOUD_RET_MQTT_CONNACK_CONNECTION_ACCEPTED |
QCLOUD_ERR_MQTT_ALREADY_CONNECTED | QCLOUD_RET_MQTT_ALREADY_CONNECTED |
MAX_SIZE_OF_DEVICE_SERC | MAX_SIZE_OF_DEVICE_SECRET |
devCertFileName | dev_cert_file_name |
devPrivateKeyFileName | dev_key_file_name |
devSerc | device_secret |
MAX_SIZE_OF_PRODUCT_KEY | MAX_SIZE_OF_PRODUCT_SECRET |
product_key | product_secret |
DEBUG | eLOG_DEBUG |
INFO | eLOG_INFO |
WARN | eLOG_WARN |
ERROR | eLOG_ERROR |
DISABLE | eLOG_DISABLE |
Log_writter | IOT_Log_Gen |
qcloud_iot_dyn_reg_dev | IOT_DynReg_Device |
IOT_SYSTEM_GET_TIME | IOT_Get_SysTime |
Was this page helpful?