I'm using MQTT broker for my IOT devicess, mostly ESP8266 ( some are NodeMCU, some Wemos mini, and some are Sonoff) , running an Arduino code, some time ( about a year ). MQTT broker is running on a RasppberryPi Zero W, flawlessly.
All devices using my own created library, including wifi connectivty and MQTT with fucntions designed for my IOT's.
Some devices (2 or 3 of out 20) - keep getting to
offline state using
keepAlive feature in MQTT (
PubSub library to be correct ), after 30 seconds defined. The second
Availabiliy state goes to
offline it updates back to
Now I'm trying to figure out the reason for it for some time, and this is the reason I decided to share:
- As said, code is mostly generic, and my wifi+mqtt is the same for all.
- If it was something to do with bad wifi signal causing MQTT lose connection to server, it should have initiate a
resetcommand using a watch dog timer for such cases ( 20 secs to reset ).
- I tried to change MQTT broker for that specific IOT to be sure it has nothing to da with the broker... and problem still persists.
My questions are :
#define MQTT_KEEPALIVE 30as defined in
PubSub.h- check only once every 30 sec or there is more than 1 check in that time interval ??
- Is there another way to check why or what might be the reason for an iot device losing connection with broker, getting to
keepAlivephase, and go right back after send that lastwill ?