Topic: wolfMQTT Published Message Incomplete

Hi Forum,

I am using wolfMQTT and MPLABX Harmony 3 with the NET-GLUE (https://github.com/Microchip-MPLAB-Harm … net_glue.h)

Using these configuration values :

#define APP_MQTT_MAX_PUBLISH_MESSAGE_SIZE   1024
#define APP_MQTT_TX_BUFF_SIZE       2048
#define APP_MQTT_RX_BUFF_SIZE       2048
#define APP_MQTT_DEFAULT_QOS            MQTT_QOS_0

The message to publish is a JSON string which is passed / filled to the mqtt context object publish buffer using snprintf :

snprintf(mqttCtx->publishMessage, APP_MQTT_MAX_PUBLISH_MESSAGE_SIZE + 1, MQTT_HW_TOPIC_PAYLOAD_TEMPLATE,
        field1,
        field2,
        ...
        ...
        fieldN);

Total length json string is about 298 characters.

To publish the message I execute :

resCode = MqttClient_Publish(&mqttCtx->mqttClient, &mqttCtx->mqttPublish);
            if (resCode == MQTT_CODE_CONTINUE)
            {
                break;
            }

The message is published successfully but the receiving broker receives randomly some messages incomplete.
Most of the time the message has LAST character missing or an extra null character at the END.

Is correct to fill "mqttCtx->publishMessage" buffer using snprintf or am I doing something wrong?

Any help is appreciated it.

Thanks

Share

Re: wolfMQTT Published Message Incomplete

Hi rlev,

Are you setting `mqttPublish.total_len` to the return value of snprintf?

Try checking in the application that the expected length is equal to the value of `mqttPublish.total_len` before calling `MqttClient_Publish`.

https://github.com/Microchip-MPLAB-Harm … ask.c#L480

The MCH example uses strlen to set the payload length, so if your application is sending JSON data, it's possible that some NULL is causing an invalid length calculation.

Thanks,
Eric @ wolfSSL Support

Re: wolfMQTT Published Message Incomplete

Thank you for feedback Eric.
I will check and let you know.

Share

Re: wolfMQTT Published Message Incomplete

Eric,

mqttPublish.total_len 

solved the issue.

Thank you very much for your help.

Share