ESP-12 nodeMcu
Both made in VS/Platformio with PubSubClient 2.8
Both connected to Mosquito MQTT in Docker.
The MQTT Client routines are exactly the same as in basic example.
Arduino Due: running module on LAN cable directly connected to the switch or to UBNT WiFi station up to 5 m from WiFi AP, the application runs w/o any problem (several days, thousands of MQTT messages, no outage). But moving out with UBNT WiFi station to distance about 20m far from AP, the client, in some period around 1-5 mins after few incoming MQTT messages, stucks in repeated reconnect error "Attempting MQTT connection...failed, rc=-2 try again in 5 seconds" where just soft/hard reboot helps, but nothing else. It is not issue of WiFi quality link (link quality checked at UBNT client, ping to either WiFi station or EthernetShield changed from 2ms to 3 ms, stable for large packets).
ESP8266 with WiFi: similar behaviour - on the desk up to 5m from AP works fine, no problem. But moving out to distance about 10m where is still very good signal strength (RSSI-71) there is the same error ending with exception, just longer period (hours). The same behaviour at different WiFi (UBNT unifi).
I operate another ESP-12 nodeMcu module with MicroPython within the same Wifi and MQTT on longer distance without any problem.
(I had the same problem from the beginning when I started with PubSubClient on the desk and I did client.loop 1x per second only. After few cycles when there was more incomming messages client failured... )
I have two applications of PubSubClient: