I see now. The thread also talks about reverting back to Arduino-ESP32 v1.0.0, which reportedely ran over 15 hours… Indicating that it might be an issue in the Arduino core, and not in the library, or Mosquitto.
But you should be able to test this.
I’d suggest the following two tests:
First of all, for all, turn on Mosquitto logging to the absolute maximum (here, log_type all
, make sure you have enough space on the SD card of the Pi). With that info one can hopefully see if Mosquitto is the one doing the disconnecting.
Then, run one ESP32 with the MQTT firmware that you say is reconnecting every 200 minutes and add
build_flags = -DCORE_DEBUG_LEVEL=5
monitor_filters = log2file, time, esp32_exception_decoder
build_type = debug
to the platformio.ini
of the project (docs). This makes it so that the “Monitor” tasks now creates a log file with all serial output, decodes exceptioins with debug-symbol information if a crash occurrs, and activates all debug output of the core (docs) with maximum verbosity.
Re-upload and monitor that firmware until you observe the disconnect again (or just let it run for more than say 205 minutes). The two log files should then very clearly show what is happening .
Another test would be to run the 1.0.0 core version and see if the error is automatically gone with that. Since the version is very old (2018) it might be a bit difficult do that in PlatformIO, you need both an old platform version and probably an old MQTT library version for it.
There can you start off of the platformio.ini
[env:esp32]
platform = espressif32@1.2.0
board = esp32dev
framework = arduino
; first version that supports ESP32
lib_deps =
https://github.com/knolleary/pubsubclient/archive/refs/tags/v2.7.zip
and try fixing errors or increasing versions from there, see here and here.