Topic: MqttMessage and handling large messages

I apologize if I missed this in the WolfMQTT manual, but I'm not clear how to receive a large MQTT message from the broker (received message is larger than the buffer passed to MqttClient_Init()).  What is the sequence of calls to the callback function for such a message, including the values of callback function parameters msg_new, msg_done, msg->buffer, msg->buffer_len and msg->buffer_pos.

If this info is in the manual, a pointer to where it is would be appreciated.

Anthony Jenkins


Re: MqttMessage and handling large messages

Hello Anthony,

The callback description is here: … ient.h#L49

The callback is registered during `MqttClient_Init`, and it will be called when a published message is received on a topic the client is subscribed to. The topic name and total payload size are available in the `MqttMessage` parameter. The msg_new and msg_done parameters are used to indicate the progress of the payload.

There is an excellent example that demonstrates receiving a large payload using the message callback functionality. It a two part example, the first client creates and publishes a signed "firmware" blob. The second client is subscribed to the topic waiting for the firmware message. When it receives the message, it saves the payload and authenticates the firmware package. … s/firmware

Instructions: … re-example

Eric @ wolfSSL Support

3 (edited by Scoobi_FreeBSD 2020-09-14 08:04:05)

Re: MqttMessage and handling large messages

Awesome, thanks!!!

Okay, to summarize for anyone also looking for this information, it looks like:

for callback function message_cb with prototype

int message_cb(MqttClient *client, MqttMessage *msg, byte msg_new, byte msg_done)
  • msg->buffer points to the start of the i'th chunk of the message received from the broker

  • msg->buffer_pos is the absolute position of the i'th chunk in the total message

  • msg->buffer_len is the length of the i'th chunk of the message received from the broker

  • msg->total_len is the sum of all msg->buffer_len (i.e. the total length of the message)

  • msg_new = nonzero for i = 0

  • msg_done = nonzero for i = n-1, where n = the number of message chunks sent (and the number of calls to the callback)