I have a Raspberry Pi Zero 2W on 32bit PiOS running the following Docker containers: Node-RED, Mosquitto, and Influxdb. I have a Seeed Studios Xiao ESP32C3 running a C program compiled by the Arduino IDE, that monitors a BMP280. In Node-Red, I have set the mqtt broker "Keep Alive" element set to 600. I also re-booted the Pi after setting this parameter.
My problem arose when I set a time delay between sequential readings of the sensor and publishing the data to the mqtt broker. The first report after resetting the Xiao comes through fine. I have programmed the Xiao to publish a log message every x seconds in a while loop that uses the
delay(x) function. If I set
x to anything more than 24 seconds (e.g.
delay(24000)), the connection to the mqtt broker is lost. I have a check for
client.connected() which re-establishes the connection if it is lost. The Arduino IDE Serial Monitor shows that the loop is running, that the mqtt broker connection is re-established, then the first report comes through, and the connection is lost again.
I seem to be missing something somewhere.