hideakitai / MQTTPubSubClient

MQTT and MQTT over WebSoket Client for Arduino

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

After 20 seconds stops receiving events

raulperez opened this issue · comments

Gets disconnected frequently and after 20 seconds without publishing any event, when I start sending events again sometimes they appear after long time, some other times the MQTT client gets disconnected from the broker...

I am calling update() every 100 ms. I have tried with different timings.

I am using WiFiEspAT library for my WiFi client.

Any idea of what could be happening?

This seems to do the trick:

void loop() {
...
long now = millis();
if (now - lastBrokerUpdate > 1000) {
lastBrokerUpdate = now;
mqtt.update();
mqtt.publish("topic/alive", ""); //required to keep alive the MQTT client connection
}
...
}

Eventually also check MQTT connection and reconnect if not connected...

Please try to change the interval and timeout.

void setKeepAliveSendInterval(const uint32_t ms);
void setKeepAliveTimeout(const uint16_t sec);