Topic: Problem to receive and publish messages in different tasks

I have problem writing multitask MQTT client for Microchip SAMV71 microprocessor using the wolfMQTT library.
The client receives the messages by calling the MqttClient_WaitMessage() in one task and publishes the responces using MqttClient_Publish() in another task.
As a result the sending and publishing is done simultaneously. The library is used in non-blocking mode (WOLFMQTT_NONBLOCK).

The code looks like that:
Receiving task:
while(MQTT_CODE_CONTINUE == !MqttClient_WaitMessage(&client, 100 /*ms*/));

Publishing task (publish structure and buffers are in static area, qos is MQTT_QOS_1 or MQTT_QOS_2):
while(MQTT_CODE_CONTINUE == MqttClient_Publish(&client, &publish));

The client crashes after few hundred messages transferred in both direction. The question is what can I do to make the sending and publishing working.

One thing I found that at some point the MqttClient_Publish() function never return the success, only MQTT_CODE_CONTINUE. It looks like it starts to read MQTT acknowledge, as part of QOS1/2 handling. The ACK packages arrives but the MqttClient_Publish() function fails to read them from socket. For me it looks like the MqttClient_WaitMessage() and MqttClient_Publish() are conflicting, because both share the same control structure: "clientpacket" in MqttClient_WaitType().

Share

Re: Problem to receive and publish messages in different tasks

Hello sricor,

Welcome to the wolfSSL Forums. This sounds like a very interesting project. If the return code is MQTT_CODE_CONTINUE, then the IO driver is returning EINPROGRESS or EWOULDBLOCK, indicating that the driver buffer is not being emptied. I'd like to try to reproduce this. Could you please send an email to support@wolfssl.com mentioning this forum post?

Thanks,
Eric - wolfSSL Support

Re: Problem to receive and publish messages in different tasks

Thank you for reply. I understand that the MQTT_CODE_CONTINUE means that the driver doesn't complete the request. That is why I have the while loop. I rely that on exit from that loop the buffer is done.

I also forgot to mention that I use the wolfMQTT library v1.7.1 that comes from Mictochip HARMONY 3 framework for SAMv71.

Share

Re: Problem to receive and publish messages in different tasks

Hi sricor,

I have responded to your ticket in our Zendesk portal. Thanks for sending that in.