Skip to content

Very slow connection to WiFi - almost 3.2 seconds, even if the static IP is used. #2798

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

Closed
robertgregor opened this issue May 20, 2019 · 3 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@robertgregor
Copy link

Hi,
I have latest 1.0.3 rc1 installed and have simple sketch:

#include <WiFi.h>

boolean connected=false;

IPAddress getIpAddr(String ip) {
IPAddress addr;
int iparr[4];
iparr[0] = ip.toInt();
for (int i=1; i<4; i++) {
ip.remove(0, ip.indexOf('.')+1);
iparr[i] = ip.toInt();
}
return IPAddress(iparr[0], iparr[1], iparr[2], iparr[3]);
}

void connectToWifiNoWait(String ssid, String pwd, String ip, String gw, String mask, String dns1, String dns2, String bssid, String chnl ) {
if (WiFi.status() == WL_CONNECTED) return;
Serial.println(PSTR("Connecting wifi..."));
WiFi.persistent(true);
WiFi.setAutoConnect(true);
WiFi.setAutoReconnect(true);
if (ip.length() != 0) {
WiFi.config(getIpAddr(ip), getIpAddr(gw), getIpAddr(mask), getIpAddr(dns1), getIpAddr(dns2));
Serial.println(PSTR("Config called..."));
}
if ((ssid.length() != 0) && (pwd.length() == 0)) {
WiFi.begin(ssid.c_str());
Serial.println(PSTR("Begin with ssid called..."));
} else if ((ssid.length() != 0) && (pwd.length() != 0)) {
if (bssid.length() == 0) {
WiFi.begin(ssid.c_str(), pwd.c_str());
Serial.println(PSTR("Begin with ssid and password called..."));
} else {
byte iparr[6];
for (int i=0; i<6; i++) {
String part = "0x" + bssid.substring(0,bssid.indexOf(':'));
bssid.remove(0, bssid.indexOf(':')+1);
iparr[i] = strtol(part.c_str(),NULL,0);
}
WiFi.begin(ssid.c_str(), pwd.c_str(), chnl.toInt(), iparr);
Serial.println(PSTR("Begin with ssid, password, channel and bssid called..."));
}
}
}

void setup() {
Serial.begin(115200);
connectToWifiNoWait("Bob", "xxxxx", "192.168.1.50", "192.168.1.1", "255.255.255.0", "94.142.233.120", "94.142.233.140", "F8:D1:11:24:B3:84", "4" );
WiFi.setAutoReconnect(true);
}

void loop() {
// put your main code here, to run repeatedly:
if (WiFi.status() == WL_CONNECTED) {
if (!connected) {
Serial.print("Connected: ");
Serial.println(millis(), DEC);
connected=true;
Serial.printf("IP: %d.%d.%d.%d, time: %d",WiFi.localIP()[0],WiFi.localIP()[1],WiFi.localIP()[2],WiFi.localIP()[3], millis());
}
}
}

As is seen, I will do simple config and then will try to connect. My problem is, that connection to wifi takes almost 3.5 seconds:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:928
ho 0 tail 12 room 4
load:0x40078000,len:8424
ho 0 tail 12 room 4
load:0x40080400,len:5868
entry 0x4008069c
Connecting wifi...
Config called...
Begin with ssid, password, channel and bssid called...
Connected: 3499
IP: 192.168.1.50, time: 3499

Any idea, what can be the problem? Almost the same code using esp 8266 was working in 100 - 200 ms.

@cendev
Copy link

cendev commented Jun 2, 2019

Ten months and issue standing still :) Just because #1675, it costs ous money, time and some sleepless nights. Using ESP32 modules would allow us to produce more robust sensors yet we are still using attiny13 + 8266 combo just to wake up from deep sleep and report under a second.

Can't give up on WPA2 to connect faster, as the issue only seen on WPA networks..
Can't give up on "Report in less than a second"
Can't give up on 8266s..

Even on IDF problem persists.

@stale
Copy link

stale bot commented Aug 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 1, 2019
@stale
Copy link

stale bot commented Aug 15, 2019

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

2 participants