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().