ESP8266 MQTT times out and doesn't reconnect?

I've been having this issue for some time now. I've got an ESP setup with a relay module to my garage door opener. When the device is freshly powered up, it works fine and responds as it should.

After a day or two, I've noticed in the MQTT logs that the device times out and then doesn't automatically reconnect.

1524836953: New connection from 192.168.1.117 on port 1883.
1524836953: New client connected from 192.168.1.117 as garage-5c:cf:7f:4c:57:50 (c1, k5, u'root').
1524837745: Saving in-memory database to /data/mosquitto.db.
1524838637: Client home-assistant disconnected.
1524838662: New connection from 172.30.32.1 on port 1883.
1524838662: New client connected from 172.30.32.1 as home-assistant (c1, k15, u'root').
1524838832: Client home-assistant disconnected.
1524838844: New connection from 172.30.32.1 on port 1883.
1524838844: New client connected from 172.30.32.1 as home-assistant (c1, k15, u'root').
1524838940: Client home-assistant disconnected.
1524841347: Saving in-memory database to /data/mosquitto.db.
1524843148: Saving in-memory database to /data/mosquitto.db.
1524844949: Saving in-memory database to /data/mosquitto.db.
1524846750: Saving in-memory database to /data/mosquitto.db.
1524871964: Saving in-memory database to /data/mosquitto.db.
1524873647: Client garage-5c:cf:7f:4c:57:50 has exceeded timeout, disconnecting.
1524873647: Socket error on client garage-5c:cf:7f:4c:57:50, disconnecting.
1524873765: Saving in-memory database to /data/mosquitto.db.
1524875566: Saving in-memory database to /data/mosquitto.db.
1524877367: Saving in-memory database to /data/mosquitto.db.

I've reduced this log a bit (lots of saving the db, and a few disconnects from the internal 172.30.32.1 IP.

I've tried coding the ESP so it sends a keep alive message to MQTT every 1 second but that doesn't seem to have helped.

Anybody have any ideas?

Posted Apr 28, 2018, 3:47 AM UTC

14
markus_b•

Your ESP code should regularly check if the connection is still alive and reconnect, if necessary.

1
stone-sfw•
1
koomOP•

thanks for that, i'll update my esp devices and see how this one goes!

1