Help Center/ IoT Device Access/ SDK Reference/ Device-side SDKs/ IoT Device Tiny C SDK/ Communication Protocol Selection and Adaptation
Updated on 2025-12-04 GMT+08:00

Communication Protocol Selection and Adaptation

The IoT Device SDK Tiny supports a comprehensive range of IoT interconnection protocols, such as MQTT, LwM2M, CoAP, Mbed TLS, and lwIP. This section will focus on detailing MQTT, LwM2M, and CoAP.

Table 1 Supported protocols

Term

Description

Message Queuing Telemetry Transport (MQTT)

An IoT transmission protocol designed for lightweight publish/subscription messaging. It aims to provide reliable network services for IoT devices in low-bandwidth and unstable network environments. MQTTS refers to the combination of MQTT and SSL/TLS. The SSL and TLS protocols are used for encrypted transmission.

Constrained Application Protocol (CoAP)

A software protocol designed to enable simple devices to perform interactive communication on the Internet. CoAPS refers to CoAP over DTLS. DTLS is used for encrypted transmission.

Lightweight Machine to Machine (LwM2M)

An IoT protocol defined by Open Mobile Alliance (OMA). It is mainly used for NB-IoT devices with limited resources (such as limited storage and power supply).

Mbed TLS

Previously PolarSSL, a set of user-friendly encryption and decryption algorithms, as well as an SSL/TLS library designed for embedded systems. Known for its minimal system overhead and resource requirements, Mbed TLS operates under the Apache 2.0 license as an open-source project. It is widely utilized in both open-source and commercial ventures, with notable implementations in projects like Monkey HTTP Daemon and Linksys routers.

Cloud Service Abstraction Layer APIs

The device-cloud interconnection component of the IoT Device SDK Tiny provides device-cloud synergy and open APIs for interconnecting with Huawei Cloud through MQTT, LwM2M, and CoAP.

Developers can connect to Huawei Cloud using MQTT, LwM2M, or CoAP protocols, along with corresponding modules for Huawei Cloud adaptation. By registering the chosen IoT protocol with the cloud service abstraction layer (OC AL) and utilizing the provided APIs, developers can seamlessly interact with Huawei Cloud without needing to delve into the specifics of the IoT protocol implementation.

  • OC-MQTT

    The directory for the MQTT abstraction layer APIs provided by OC AL is located at \iot_link\oc\oc_mqtt. For details about the MQTT device-cloud interconnection APIs offered by OC AL, refer to the latest oc_mqtt_al.h file. The table below lists the APIs.

    Directory

    Description

    .../oc_mqtt_al

    Adaptation to the MQTT abstraction layer of the Huawei Cloud IoT platform. Functions registered by the user are called during the registration.

    .../oc_mqtt_tiny_v5

    Implementation for adaptation of built-in software devices of the SDK to OC service MQTT. (for the cloud V5 APIs).

    .../oc_mqtt_profile_v5

    Built-in product model-based APIs of the SDK, with topics parsed and data formats defined.

  • OC-LwM2M

    The directory for the LwM2M abstraction layer APIs provided by OC AL is located at \iot_link\oc\oc_lwm2m. For details about the LwM2M device-cloud interconnection APIs offered by OC AL, refer to the latest oc_lwm2m_al.h file. The table below lists the APIs.

    Directory

    Description

    .../oc_lwm2m_al

    LwM2M abstraction layer APIs and implementation. Adaptation functions at the bottom layer are called during the registration.

    .../atiny_lwm2m

    Implementation for adaptation of built-in software devices of the SDK to LwM2M. Related functions can be registered with the SDK by using the oc_lwm2m_register function provided by the abstraction layer.

    .../oc_lwm2m_imp/boudica150

    The built-in boudica150 of the SDK adapts to the LwM2M implementation of the Huawei IoT platform. Related functions can be registered with the SDK by using the oc_lwm2m_register function provided by the abstraction layer.

  • OC-CoAP

    The directory for the CoAP abstraction layer APIs provided by OC AL is located at \iot_link\oc\oc_coap. For details about the CoAP device-cloud interconnection APIs offered by OC AL, refer to the latest oc_coap_al.h file. The table below lists the APIs.

    Directory

    Description

    .../oc_coap_al

    OC CoAP abstraction layer APIs and implementation. Adaptation functions at the bottom layer are called during the registration.

    .../atiny_coap

    Implementation for adaptation of built-in software devices of the SDK to CoAP. Related functions can be registered with the SDK by using the oc_coap_register function provided by the abstraction layer. |

IoT Component Protocol Layer

The IoT Device SDK Tiny integrates IoT standard protocols such as LwM2M, CoAP, and MQTT. You can directly invoke these protocols or add and register a custom protocol with the SDK. The protocol layer directory is \network\.

  1. MQTT AL

    The MQTT service provided by the IoT Device SDK Tiny is based on the standard MQTT protocol and provides MQTT abstraction layer APIs. The following figure shows the MQTT software architecture.

    typedef struct
    {
       ///< connect to the server
       void* (* connect)   (mqtt_al_conpara_t *param);
       ///< disconnect from the server
       int    (* disconnect)(void *handle );
       ///< publish a message to the server
       int	   (* publish)    (void *handle, mqtt_al_pubpara_t *msg);
       ///< subscribe a topic to the server
       int    (* subscribe)   (void *handle, mqtt_al_subpara_t *subpara);
       ///< unsubscribe a topic to the server
       int    (* unsubscribe) (void *handle, mqtt_al_unsubpara_t *unsubpara);
       ///< check the mqtt engine status
       en_mqtt_al_connect_state (* check_status) (void *handle);
    }mqtt_al_op_t;
    int mqtt_al_install(mqtt_al_op_t *op);
    Table 2 MQTT abstraction layer APIs

    API Category

    API

    Description

    MQTT APIs

    void * mqtt_al_connect( mqtt_al_conpara_t *conparam)

    Requesting a connection

    int mqtt_al_disconnect(void *handle)

    Breaking the connection

    int mqtt_al_publish(void *handle, mqtt_al_pubpara_t *pubpara)

    Publishing a message

    int mqtt_al_subscribe(void *handle, mqtt_al_subpara_t *subpara)

    Requesting a subscription

    int mqtt_al_unsubscribe(void *handle, mqtt_al_unsubpara_t *unsubpara)

    Canceling a subscription

    en_mqtt_al_connect_state mqtt_al_check_status(void *handle)

    Checking the connection status

  2. LwM2M AL

    The LwM2M service provided by the IoT Device SDK Tiny is based on the standard LwM2M protocol and provides LwM2M abstraction layer APIs. The following figure shows the LwM2M software architecture.

    typedef struct
    {
        /* lwm2m config, prepare endpoint name and message deal callback */
        int (*config)(void **handle, lwm2m_al_init_param_t *init_param);
    
        /* lwm2m deinit */
        int (*deconfig)(void *handle);
    
        /* lwm2m add object */
        int (*add_object)(void *handle, int object_id, int object_instance_id, int resource_id, void *param);
    
        /* lwm2m delete object */
        int (*delete_object)(void *handle, int object_id);
    
        /* lwm2m connect */
        int (*connect)(void *handle);
    
        /* lwm2m disconnect */
        int (*disconnect)(void *handle);
    
        /* lwm2m send */
        int (*send)(void *handle, lwm2m_al_send_param_t *send_param);
    } lwm2m_al_op_t;
    Table 3 LwM2M abstraction layer APIs

    API Category

    API

    Description

    LwM2M APIs

    int (*config)(void **handle, lwm2m_al_init_param_t *init_param);

    Initializing configuration

    int (*deconfig)(void *handle);

    Canceling the initialization

    int (*add_object)(void *handle, int object_id, int object_instance_id, int resource_id, void *param);

    Adding an object

    int (*delete_object)(void *handle, int object_id);

    Deleting an object

    int (*connect)(void *handle);

    Requesting a connection

    int (*disconnect)(void *handle);

    Breaking the connection

    int (*send)(void *handle, lwm2m_al_send_param_t *send_param);

    Sending

  3. CoAP AL

    The CoAP service provided by the IoT Device SDK Tiny is based on the standard CoAP and provides CoAP abstraction layer APIs. The following figure shows the CoAP software architecture.

    typedef struct
    {
       ///< coap init, prepare context, session, etc
       int    (* init)     (coap_al_initpara_t *initparam);
       ///< coap deinit
       int    (* deinit)   (void *handle);
       ///< coap add option
       void*  (* add_opt)  (coap_al_optpara_t *optparam);
       ///< new coap request
       void*  (* request)  (coap_al_reqpara_t *reqparam);
       ///< send a request to server
       int	   (* send)     (coap_al_sndpara_t *sndparam);
       ///< recv and handle response from server
       int    (* recv)     (coap_al_rcvpara_t *rcvparam);
    }coap_al_op_t;
    int coap_al_install(coap_al_op_t *op);

    The table below describes related adaptation APIs.

    API Category

    API

    Description

    CoAP APIs

    int coap_al_init(coap_al_initpara_t *initparam);

    Initializing

    int coap_al_deinit(void *handle);

    Canceling the initialization

    void *coap_al_add_option(coap_al_optpara_t *optparam);

    Adding a CoAP option

    void *coap_al_new_request(coap_al_reqpara_t *reqparam);

    Creating a message request

    int coap_al_send(coap_al_sndpara_t *sndparam);

    Sending a message to the server

    int coap_al_recv(coap_al_rcvpara_t *rcvparam);

    Receiving and processing data delivered by the server

    int coap_al_install(coap_al_op_t *op);

    Registering the protocol stack with the system

    int coap_al_uninstall();

    Canceling the registration