For MCUs without network communication capability, generally use the way of MCU + Communication Module. The Communication Module (including Wi-Fi/2G/4G/NB-IoT) generally provides an AT Command Protocol based on the serial port for the MCU to perform network communication. Targeting this type of scenario, the C SDK encapsulates the AT-socket network layer. The core protocol and service layer above the network layer do not need to be ported.
Compared with the scenario with RTOS, the handling of server downlink data reception by the AT-socket network may vary. The application layer needs to periodically call IOT_MQTT_Yield to receive server downlink data. Missing the reception window may result in data loss. Therefore, in scenarios with relatively complex business logic, it is recommended to use RTOS and select the no-OS method by configuring
FEATURE_AT_OS_USED = OFF.SDK Acquisition
The SDK is hosted on Github and the latest version of the device-side C SDK can be downloaded from Github.
Integration Guides
Integrating MCU + common TCP AT module (nonOS) with Tencent Cloud IoT Explorer can be divided into the following 4 steps.
SDK Feature Configuration
Use general TCP module compilation configuration options without RTOS. Configuration as follows:
Name | Configuration | Overview |
BUILD_TYPE | debug/release | Set according to needs. |
EXTRACT_SRC | ON | Enable code extraction. |
COMPILE_TOOLS | gcc/MSVC | Set according to needs. Ignore IDE situations. |
PLATFORM | Linux/Windows | Set according to needs. No need to focus on IDE situations. |
FEATURE_OTA_COMM_ENABLED | ON/OFF | Set according to needs. |
FEATURE_AUTH_MODE | KEY | It is recommended to choose key authentication as the authentication method for resource-constrained devices. |
FEATURE_AUTH_WITH_NOTLS | ON/OFF | Enable TLS as required. |
FEATURE_EVENT_POST_ENABLED | ON/OFF | Enable event reporting as required. |
FEATURE_AT_TCP_ENABLED | ON | Enable the AT-socket component. |
FEATURE_AT_UART_RECV_IRQ | ON | Enable AT Serial Port Interrupt Reception. |
FEATURE_AT_OS_USED | OFF | The AT-socket component is not used in the RTOS environment. |
FEATURE_AT_DEBUG | OFF | The debugging feature of the AT Module is off by default and can be enabled when debugging is required. |
Code Extraction
1. Run the following commands in a Linux environment:
mkdir buildcd buildcmake ..
2. You can then find the related code files in output/qcloud_iot_c_sdk. The directory hierarchy is as follows:
qcloud_iot_c_sdk├── include│ ├── config.h│ ├── exports├── platform└── sdk_src└── internal_inc
Note:
include directory: SDK provides users with API used and variable parameters, among them config.h is a compilation macro generated according to compilation options.
platform directory: Platform-related code, which can be modified and adapted according to the specific situation of the device.
sdk_src: The core logic and protocol-related code of the SDK, generally do not need to be modified, among them internal_inc is a header file for internal use of the SDK.
3. Users can copy qcloud_iot_c_sdk to the compilation development environment of their target platform and modify the compilation options as appropriate.
HAL Layer Porting
For network-related HAL interfaces, the SDK-provided AT_Socket framework has been selected through the compilation options in this document. The SDK will call the
AT-socket interface of network_at_tcp.c. The AT-socket layer does not need to be ported. You need to implement the AT Serial Port Driver and the AT Module Driver. For the AT Module Driver, only the driver interface of the driver structure AT_device_op_t of AT_device in the AT Framework needs to be implemented. You can refer to the supported modules under the AT_device directory. The AT Serial Port Driver needs to implement the interrupt reception of the serial port, and then call the callback function AT_client_uart_rx_isr_cb in the interrupt service program. You can refer to HAL_OS_nonos.c to implement the porting of the target platform.