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:
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);
uint8_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 Would be nice to reduce the time spending 80mA (when using WiFi) further to improve battery life.
Thanks & best!