The use of the ESP8266 in the world of IoT

User avatar
By Terraformer
#53177 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!
User avatar
By schufti
#53651 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.
User avatar
By Terraformer
#53673 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!