256dpi / arduino-mqtt

MQTT library for Arduino
MIT License
1.01k stars 232 forks source link

connect timeout #247

Closed alirezaimi closed 1 year ago

alirezaimi commented 3 years ago

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);
256dpi commented 3 years ago

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.

alirezaimi commented 3 years ago

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

alirezaimi commented 3 years ago

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

256dpi commented 1 year ago

Closing as stale. Please reopen if issue persists.

alirezaimi commented 1 year ago

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 commented 1 year ago

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

what is this option ?