-->
Page 1 of 2

ESP-01: 1900ms to connect to WiFi - further improvements?

PostPosted: Wed Aug 17, 2016 4:20 pm
by Terraformer
Hi,

I have some ESP-01 modules which use the following code to connect to local the router in 1800 to 1900ms after initial boot and deep sleep, respectively:
Code: Select all  unsigned long ts = millis();
  if (WiFi.status() == WL_CONNECTED) {
    return true;
  }

      IPAddress ip(192,168,0,50+devID);
      IPAddress gateway(192,168,0,1);
      IPAddress subnet(255,255,255,0);
      WiFi.config(ip, gateway, subnet);
      uint8_t bssid[6] = {12,32,123,87,187,56};
      WiFi.begin(ssid.c_str(), password.c_str(), 4, bssid);

    int imax = WLAN_TRIES;
    int x=0;
   
    delay(500); // Wait for connection
    while (WiFi.status() != WL_CONNECTED) {
      delay(100+x*20); x++;
      imax--;
      if (imax == 0) {
        return false;
      }
    }   
  unsigned long tr = millis()- ts;
  iTime2Connect = (int)(tr / 1000L);
Note that the following line reduced the time to connect from 4100ms to 1900ms!
Code: Select alluint8_t bssid[6] = {12,32,123,87,187,56};
      WiFi.begin(ssid.c_str(), password.c_str(), 4, bssid);

I've searched the forum and the web repeatedly. Any further suggestions to reduce connection time? I read somewhere that some have modules that connect in less than 500ms :o Would be nice to reduce the time spending 80mA (when using WiFi) further to improve battery life.

Thanks & best!

Re: ESP-01: 1900ms to connect to WiFi - further improvements

PostPosted: Tue Aug 23, 2016 2:52 am
by erbedo
Did you do any other optimization? I tried your code, and in my setup the time to connect is around 4 seconds, which is still a bit high.

Re: ESP-01: 1900ms to connect to WiFi - further improvements

PostPosted: Tue Aug 23, 2016 6:17 am
by schufti
depends a lot on type of authentication, encryption and router.

WEP, WPA and WPA2 have increasing level of complexity as do tkip and aes nave increasing demands on cpu power.

it should be clear that in the example above
uint8_t bssid[6] = {12,32,123,87,187,56};
should be replaced with the MAC representation of your AP.

Re: ESP-01: 1900ms to connect to WiFi - further improvements

PostPosted: Tue Aug 23, 2016 12:22 pm
by Terraformer
Hi erbedo,

I think you had the wrong MAC address because that did the trick for me, see schufti's note.
To clarify my setting a bit. The (old) router uses a fixed channel, SSID broadcasting is active, 802.11b/g, WPA-PSK/WPA2-PSK with AES/TKIP.
The distance between router and ESPs vary from 3 to 9 meters (through 1 to 3 walls).

Best!