arduino-mqtt icon indicating copy to clipboard operation
arduino-mqtt copied to clipboard

connect timeout

Open alirezaimi opened this issue 3 years ago • 3 comments

Hi

When my internet connection lost, my loop function run every 9 seconds because stuck in mqtt connection and publish part of code. why ? and how can pass this part if internet connection lost and doest stuck in seconds that i define somewhere ? is there any param for connect method ?

in setup :

  ...
  ///// mqtt
  mqttclient.setOptions(5, true, 500);
  mqttclient.begin(MQTT_SERVER, MQTT_SERVERPORT, WiFiclient);
  mqttclient.onMessage(messageReceived);
  mqtt_connect();
  ...
  
  

in loop :

...
mqttclient.loop();
...

delay(1000);

and some where in my code define mqtt_connect func :

void mqtt_connect() {
  WiFiclient.setInsecure();
  Serial.println(">> connecting to broker...");
  mqttclient.connect("MQTT-client-imi-arduino", MQTT_USERNAME, MQTT_PASSWORD);

alirezaimi avatar May 03 '21 19:05 alirezaimi

This is a known problem. The common Arduino APIs do not yet expose a way to set a connect timeout. Depending on your platform you might find a way to tweak the network implementation to use a lower timeout.

256dpi avatar May 04 '21 07:05 256dpi

sad :( Is setting timeout in this option can help me ? void setOptions(int keepAlive, bool cleanSession, int timeout);

alirezaimi avatar Jul 16 '21 09:07 alirezaimi

I can't find out any way because I can't understand the real problem cause my this issue :((((

alirezaimi avatar Jul 21 '21 08:07 alirezaimi

Closing as stale. Please reopen if issue persists.

256dpi avatar Feb 04 '23 10:02 256dpi

The main problem is still exist ! and the timeout option is very important option that when the internet connection lost handle this problem and pass it right away without any delayed .

alirezaimi avatar Mar 14 '23 12:03 alirezaimi

what about this parameter (timeout) : void setOptions(int keepAlive, bool cleanSession, int timeout);

what is this option ?

alirezaimi avatar Mar 14 '23 12:03 alirezaimi