MQTT Client Message Object Setup

Message's Parameters

µC/MQTT-client provides the function MQTTc_MsgSetParam to configure parameters related to the MQTT message. The function takes as argument the type of parameter and the pointer to the parameter. The following parameter types are available :

Table - MQTTc Message Parameters
Parameter TypeDescription
MQTTc_PARAM_TYPE_MSG_BUF_PTRSets the Message's buffer start.
MQTTc_PARAM_TYPE_MSG_BUF_LENSets the Message's maximum buffer length.


Example

Listing - MQTTc Message Configuration Example
static  MQTTc_MSG    AppMQTTc_Msg;
static  CPU_INT08U   AppMQTTc_MsgBuf[APP_MQTTc_MSG_LEN_MAX];


CPU_BOOLEAN  App_MQTTc_MsgPrepare (void)
{
    MQTTc_ERR  err;


                                                                 /* ----------------- INIT NEW MESSAGE ----------------- */
    MQTTc_MsgClr(&AppMQTTc_Msg, &err);
    if (err != MQTTc_ERR_NONE) {
        return (DEF_FAIL);
    }

    MQTTc_MsgSetParam(&AppMQTTc_Msg, MQTTc_PARAM_TYPE_MSG_BUF_PTR, (void *)&AppMQTTc_MsgBuf[0u], &err);
    if (err != MQTTc_ERR_NONE) {
        return (DEF_FAIL);
    }

    MQTTc_MsgSetParam(&AppMQTTc_Msg, MQTTc_PARAM_TYPE_MSG_BUF_LEN, (void *)APP_MQTTc_MSG_LEN_MAX, &err);
    if (err != MQTTc_ERR_NONE) {
        return (DEF_FAIL);
    }

    return (DEF_OK);
}