Open MuhammadOsaid opened 4 years ago
ESP8266 is connected to WiFi and connection to server is successfully established. I am using
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
For testing purpose the Internet is deliberately switched off from the WiFi router (WiFi is still connected).
client.publish()
rightfully returns false but when the client state is checked usingclient.state()
it returns 0 i.e. MQTT_CONNECTED ref:https://pubsubclient.knolleary.net/api.html#stateThis keeps on happening four times. The fifth time client.state() returns
MQTT_CONNECTION_TIMEOUT
Kindly look into this.
I have a similar environment, when connected, no problem, if I physically disconnect the MQTT server, state () and connected () continue to mark connected, it does not mark time out
Hello, I also discovered this kind of problem:
-ESP32 establish a MQTT connection to the MQTT broker -the ESP32 send a MQTT Message every 3 seconds -Now I disconnect the MQTT broker from the network -Client.state() return 0 (MQTT_CONNECTED) and the serial monitor says a message was send -This continue for 25 minutes -After 25 minutes Client.state() return -2 -Now the ESP32 try to reconnect to the MQTT broker
That is way to long until the client detects the connection loss, anyone has an idea?
If you have calls to client.loop() (which inherently calls client.connected()) or client.connected (which updates client._state ) just before client.state() checks, it will most likely yield correct state.
ESP8266 is connected to WiFi and connection to server is successfully established. I am using
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
For testing purpose the Internet is deliberately switched off from the WiFi router (WiFi is still connected).
client.publish()
rightfully returns false but when the client state is checked usingclient.state()
it returns 0 i.e. MQTT_CONNECTED ref:https://pubsubclient.knolleary.net/api.html#stateThis keeps on happening four times. The fifth time client.state() returns
MQTT_CONNECTION_TIMEOUT
Kindly look into this.