-
Notifications
You must be signed in to change notification settings - Fork 13.3k
WiFiClient.connect slow the first time #506
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
Comments
the most time takes the DHCP request. switching to static IP speed it up. |
Maybe your first connect makes a DNS resolve call which might take time too. Try to connect to IP-Address directly. |
Static ip + channel + BSSID : |
Thanks for the comments. Some follow up replies:
|
It turns out this is caused by not calling WiFi.status() to see if its connected before starting the WiFiClient.connect. More about that here. |
@chaeplin: Can u provide a quick and dirty example how to pre-set bssid and channel? |
Looks like you can specify them on the WiFi.begin call. Here's the function in ESP8266WiFi.h:
|
I wonder if there could be a bug in WiFiClient.connect that makes it slow to connect the first time its used?
I'm trying to have a battery powered ESP wakeup from deep sleep connect to a wifi access point, do an http get to publish some data, and then go back to sleep. And do that as quickly as possible to conserve battery power. Have it down to around 2 seconds now and adding in some printlns of millis() at various places in the code shows most of that time is taken up by the WiFiClient.connect call which takes about 1649 milliseconds.
That 1649ms time is fairly consistent too, occasionally its higher but often exactly 1649, which seems interesting.
I've tried running the ESP at both 80Mhz and 160 Mhz and that doesn't change that connect time significantly so its not cpu thats causing that time.
To avoid internet delays i've set up a test service on a local pc on the same wifi network, so its not some internet delay, and a Java http client running on a different pc on the same wifi network can connect to it in just a millisecond or so so its not caused by a slow network or wifi.
Also doing multiple WiFiClient.connect's on the ESP its only the first time that its >= 1649 and subsequent ones take just 12 milliseconds or so. This is using an IPAddress too not a domain name so i don't think its some dns caching thing.
Any ideas what could be causing this or what i could try to reduce that first connect time?
The text was updated successfully, but these errors were encountered: