AutoConnect does not work all the time
I used the example of WiFiManager AutoConnect to connect to my wifi network. The first time he got in the other can not. Why that ? I must disconnect, what am I doing wrong? The following log made by AutoConnect sketch. I also tried it with a sketch not based on WiFiManager using directly ESP8266WiFi API, but got the exact same problem: The first time connecting OK, in the other the connection returns error - sometimes 0, sometimes 4. Grateful. AutoConnectLog.txt
I have the same issue.
There are a few potential issues that i ve seen similar to this:
- low quality/ not powerful enough supply
- using sdk 1.5.0 (install 2.0.0 stable or 2.1.9 rc1 or latest github)
- router doesn t like esps - i have on that only connects once a day...
- faulty esp modules
Hello, i have this similar issue since yesterday, previously it was working fine. I tested the ESP and it seems OK, because i can get connected to WiFi via AT commands. I have 2 extra things to check.
1.- First the connect time via AT commands is about 3 seconds. But if try the wifiManager it quits instantly witch connect error 0, even with the correct configuration SSI/password. How can i check what is going on? why do not connect? is there an timer wich can be extended to wait a couple of extra seconds?
2.- And second, yestedary i upgraded to Arduino IDE 1.6.7... is that versión verified OK?
edit ESP core versión 2.0.0 wifimanger 0.5.0
I made a little change on the library;
I check if the there is a ssid saved on ESP. If true, I do WiFi.begin() call, without credentials.
Apparently called with no arguments, using existing credentials, it is more efficient.
The code:
/*
*odi begin
*/
int wifiMode = WiFi.getMode();
if ( !(wifiMode == WIFI_STA || wifiMode == WIFI_AP_STA) )
WiFi.mode(WIFI_STA);
DEBUG_WM(F("\nWiFi.getMode():"));DEBUG_WM(WiFi.getMode());
if ( !(ssid.equals("")) ){
DEBUG_WM(F("Trying to connect with saved credentials..."));
WiFi.begin();
int connRes;
for (int i=0; i<11; i++)
if ( (connRes = WiFi.waitForConnectResult()) == WL_CONNECTED )
break;
DEBUG_WM ("Connection result: ");
DEBUG_WM ( connRes );
if (connRes == WL_CONNECTED)
return true;
}
/*
*odi end
*/
into autoConnect() method from WiFiManager.cpp, after line 113 This works for me.
I think the ESP module needs to be "awakened".
If I stop access for a few minutes, so I do a hard reset, I get WL_NOT_CONNECTED (4) and then to give a second hard reset, I get WL_CONNECTED (3)
It is possible to set a greater "timeout" to WiFi.waitForConnectResult() call ?
Where is the low level functions used by the WiFi modules -
wifi_softap_get_config()
wifi_station_get_connect_status()
wifi_get_opmode()
status()
...
and others ? I searched, but apparently these functions are compiled, must belong to some library included in the link stage. Without source, without doc... we do not know how to access them. I found some documentation: https://github.com/CHERTS/esp8266-devkit/tree/master/Espressif Can someone confirm that the WiFi libraries hear use this espressif libraries ? There is a lot of documentation there.
the esp8266 core for arduino uses the expressif sdk to build upon. version 1.3 i think in stable and 1.5.1 in latest github
i will experiment with your change and see about adding it
btw, i am doing tests all the time with ssid blank (since i am resetting the settings a lot to test), and this didn t really happen to me at all
i won t be able to release a new version (0.7) until they release esp8266 core 2.1.0 or at least a new rc because i added some new function call, so it may be a while
i am on arduino ide 1.6.6, have not tested with 1.6.7 yet
Update, i quit Arduino IDE 1.6.7, and continue testing with ... (By the way... I'am using an ESP8266-01)
- Arduino ide 1.6.6. Esp core 2.0.0. wifimanager 0.5.0 - OK With wifimanager 0.6.0 iam getting the same compile error as this other issue #72. Is something wrong with ESP model?
- Arduino ide 1.6.5. Esp core 2.0.0. wifimanager 0.5.0 - OK wifimanager 0.6.0 - OK
BUT, i still have the issue with "Connection result: 0" I get in wifimanger url and configured again the SSID/Password, and i had "Connection result: 0". Then i reset the ESP and get "Connection result: 3, connected OK" The connection process has a wait, because it takes a couple of second to connect. When i get "Connection result: 0" it is displayed at once, no wait.
I have same issue on ESP-12. When connection fails (for example, cable provider resets modem or executes maintenance network) it will no longer connect. It will display connection result:0 and quickly opens a accesspoint. In debugging I do see my Wifi SSID and username and password it doesn't try to connect at all. I'm now testing the code from odi to see if this will help.
guys, i ve made some changes to the connection code as suggested here and added an example that soft resets if connection is not successful and tries again. could you give it a try, see if it improves anything for you?
I found if I have a delay() after serial.begin(), then wifimanager wont connect, this is with latest 2.1.0-rc2 and v0.8.0 of wifimanager. removing delay it works.
btw, if you have that delay, does the config portal get an ip or 0.0.0.0 ?
Hi, no the AP doesn't start, for me it hung after "Using last saved values, should be faster". Just sits there forever, which is bad because it locked up my sensor project for many hours, no watchdog restart or anything. Its running on a NodeMCU v0.9 powered by a 1A macbook USB port, so I would imaging the power supply is adequate.
weird, maybe some more of this weirdness related to connecting will be sorted in 1.5.2 whenever they add it to the arduino core...
if you can get similar results with a simple sketch with delay and WiFi.begin(...) it may be worth opening a ticket on the arduino core
The issue appears to be that WiFi.waitForConnectResult() can end up in an infinite loop if it can't connect to the AP. So recommend avoiding this call. I built my own while loop including a timeout.
// int connRes = WiFi.waitForConnectResult(); // this ends up in infinite loop
while(WiFi.status() == WL_DISCONNECTED && !timeout) {
delay(200);
timeout = i++ > 100;
Serial.print(".");
}
if (timeout) {
DEBUG_WM ("Connection timed out: ");
return 0;
}
never seen it locking up before i think.. i ll look at the class itself later
does the loop work ok for you? now i m thinking that maybe waitForConnectResult quits too fast as well causing some issues others are reporting...
i looked at WiFi.waitForConnectResult() and it makes sense to revert to something like your version. will change it as soon as i can
@mtnbrit i have added a new option to WiFiManger to set a connect timeout. it uses a loop similar to yours.
in order to use this you d need to update to the latest github version of the lib and call
wifiManager.setConnectTimeout(30);
before autoConnect. time in settings.
if you could give it a try before i release it on lib manager, it would be much appreciated...
Ive noticed that if wifiManager autoConnect is called when wifi is already connected, it wont reconnect and would normally hang up on waitforConnectResult. Now i have the timeout in there, it times out.
So its up the user to check if wifi.status is connected before calling wifiManager autoConnect, or I could suggest including a WiFi.isConnected() check early on the autoConnect function to return if we are already connected.
that s a bit of a weird behaviour as in the main WIFI class, if configuration doesn t change, it just returns..
if(sta_config_equal(current_conf, conf)) {
DEBUGV("sta config unchanged");
return status();
}
also the loop checks if connected
if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) {
keepConnecting = false;
}
so it should return immediately, as you are already connected... i think somehow your configuration drives it to run around in circles i will try to make some simplified test sketches that we could use to report issues to main esp8266 core cheers