Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect timeout is always 5 sec #1024

Open
wavoigt opened this issue Aug 15, 2023 · 2 comments
Open

connect timeout is always 5 sec #1024

wavoigt opened this issue Aug 15, 2023 · 2 comments

Comments

@wavoigt
Copy link

wavoigt commented Aug 15, 2023

Hi,
i'm using a battery powered ESP8266 and PubSubClient (latest version) with Home Assistant on Raspi3 and Mosquitto Broker.
Normally, all is working fine.
Now, if in case of a blackout the mosquitto Broker is unreachable, the connect function of PubSubClient has a timeout of 5 seconds.
this is too long for my battery powered equipment.
I tried to use setSocketTimeout(1) before using connect() but nothing is changing.
Setting MQTT_SOCKET_TIMEOUT to 1 in PubSubClient.h also does not change anything.

@wavoigt
Copy link
Author

wavoigt commented Aug 15, 2023

Now, i found the solution for myself:

for Windows in: C:\Users\xxxx\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266WiFi\src\WiFiClient.cpp
line 80 and 87 _timeout = 1000; (original 5000)

`WiFiClient::WiFiClient()
: _client(0), _owned(0)
{
_timeout = 1000; // was 5000
WiFiClient::_add(this);
}

WiFiClient::WiFiClient(ClientContext* client)
: _client(client), _owned(0)
{
_timeout = 1000; // was 5000
_client->ref();
WiFiClient::_add(this);
setSync(defaultSync);
setNoDelay(defaultNoDelay);
}
`
I'm wondering why it is hardcoded, so one normally can't change.
I know, it is not the best way to make changes in libraries, but i had no better idea.
For me, a timeout of 1000ms is sufficient, maybe in other applications it could be too low.

@warnerthuis
Copy link

I use the lib on a thermostat with an ESP8266 with another library OpenTherm and the heater requires as I understand that at least EVERY 1SECOND a call is done to the routine. The effect is in my case, I think,that if my thermostat loses contact with the server the heater is turned on. So I want this routine to be non-blocking with the connect command OR return within say 800ms,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants