knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.82k stars 1.47k forks source link

PubSubClient gets disconnected from MQTT on ESP32 with W5500 ethernet #639

Open jozala opened 5 years ago

jozala commented 5 years ago

While using ESP32 with W5500 (ethernet), PubSubClient gets disconnected from MQTT broker from time to time (time periods differs significantly - from few minutes to couple of hours).

Looks like PubSubClient is sending malformed TCP/MQTT packet which looks like Disconnect Req, but with very high Msg Len. It causes messages afterwards to be treated as continuation of this message. That includes Ping Request message. After "keep alive" timeout (in my case 15sec x2) PubSubClient decides to disconnect as it has not received Ping Response message.

Please find Wireshark file with section of captured packages attached (packet number 136 is the problematic one). 04-07-2019_long_tcp_packet.zip

Hardware used:

Additional information

Mosquitto MQTT broker is set up in local network. I've tried to test Ethernet client itself, by sending messages to TCP server for 24 hours and I haven't spotted any problems. That's why I believe problem might be in PubSubClient, but I wasn't able to find where. In case this is important - code I am using is on GitHub: https://github.com/maniekq/ESP32_W5500_MQTT

jozala commented 5 years ago

After another round of testing with raw TCP connection I think I was able to reproduce the same issue without PubSubClient. I've created issue for Ethernet library: https://github.com/arduino-libraries/Ethernet/issues/106 .

marcoavaccaro commented 3 years ago

Hello guys, i'm trying to connect to AWS wich request:

wifiClient.loadCACert(ca); wifiClient.loadCertificate(client_cert); wifiClient.loadPrivateKey(client_key);

Via wifi i can do it with no problems. But the ethernet library present on arduino do not have these 3 classes above.

Someone know how to connect to AWS via ethernet shield using ESP32?

pbassut commented 7 months ago

Hey, Ran into this issue and it was because I was calling mqttClient.publish with an empty string as the topic.