I recently took Losant’s provided ESP8266 MQTT example found in their Github here → Link to Repo
After adding code to manage load switching and reporting state and a few other attributes, I am constantly running into the issue of hitting the “Keepalive Timeout” error. When using PlatformIO, I ensured the maximum packet size was set to 256 or higher (#define MQTT_MAX_PACKET_SIZE 512) within the “LosantDevice.h” file. As you can see, I am at 512 as of right now.
As the error continued to persist, I added “device.loop()” to occur more frequently within the functions that house the load switching itself which is roughly every second or so. I will say, that did help the error for about 4 hours of a test run, however, still having this issue continue.