MQTT disconnection problem

Hi Zerynth Team,

I built a prototype with Esp32 devkitC and Raspberry Pi4.
A MQTT broker has been installed on the Raspberry Pi.
The Raspberry Pi sends various commands to the Esp32 devkitC using MQTT.
At the beginning, they work well. However, if I don’t send the MQTT command for a while, the MQTT connection is disconnected. From then on, the esp32 no longer receives MQTT commands from the Raspberry Pi. If I restarts the esp32 devkit, then the mqtt works well again. After that, the above problem occurs again.
I tested the MQTT publish and subscribe function on the Raspberry Pi using the same topic. It is still working well. It means there is no issue on the MQTT broker.
I think the MQTT connections between the esp32 and the devkitC is disconnected.
Is there any solution for this problem?
Previously, I sent mqtt commands directly to esp32 from the AWS EC2 server. At that time, this problem did not occur.
Should I check the status of the mqtt connection periodically on the esp32 firmware?

I really hope you get back to me soon with the best solution.

Thanks in advance.
Anatoli.

Could you tell me what do you mean by this sentence?
I suggest you run an MQTT example and test if the connection drops suddenly.
You can test mqtt by running Zerynth device manager example for instance. or running LWMQTT example.
and you can check if the connection is droped by using the connected() function and reconnect if so.

Let me know your thoughts.

Hi @karimhamdy1
Thanks for your help.
I fixed the issue. When I set the keepalive from 60 to 0, the error no longer appeared.
It is working well.

Instead, I have another problem. If I reboot my Pi4, the esp32 can no longer send data to the Pi serve even if the Pi server recovers again.
It occurs HTTPConnectionError.
I tried to send the same data to the Pi server using the dame API by Postman tool. It worked correctly.
If I reboot the esp32 board, then the esp32 sends data to the Pi sever correctly again.
So I think there is a problem on the ESP32 side.
What do you think.
The ESP32 should automatically recover data transmission after the server is restarted.
I hope you can get back to me with a good solution.

Thanks.
Anatoli.

you can catch that error, and if the error is triggered you can check if it is still connected by the function connected(), and connect again if needed
by putting the line of code that through the error in try and catch block.