-
Notifications
You must be signed in to change notification settings - Fork 13.3k
WiFi.begin doesn't connect if connection was already established #2186
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
Comments
Will you post your sketch? I can try reproducing that issue. |
"Millis ()" is strange? |
Hi igrr, Must use ESP8266 Arduino from: Works great with Adafruit's Huzzah ESP board & Feather Adafruit invests time and resources providing this open source code, Written by Tony DiCola for Adafruit Industries. #if ESP01 // testing with ESP-01 #if THING // testing with Sparkfun THING #if SWEETPEA // testing with SweetPea #if SONOFF // WiFi controlled power relay //#define PULLUP true /************************* WiFi Access Point *********************************/ #define WLAN_SSID "T-Mobile Broadband96" /************************* Adafruit.io Setup *********************************/ #define AIO_SERVER "io.adafruit.com" /************ Global State (you don't need to change this!) ******************/ // Create an ESP8266 WiFiClient class to connect to the MQTT server. // Store the MQTT server, username, and password in flash memory. // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. /****************************** Feeds ***************************************/ // Setup a feed called 'photocell' for publishing. const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell"; // Setup a feed called 'onoff' for subscribing to changes. /*************************** Sketch Code ************************************/ // Bug workaround for Arduino 1.6.6, it seems to need a function declaration void setup() { // Connect to WiFi access point. WiFi.begin(WLAN_SSID, WLAN_PASS); Serial.println("WiFi connected"); // Setup MQTT subscription for onoff feed. void loop() { // this is our 'wait for incoming subscription packets' busy subloop Adafruit_MQTT_Subscribe *subscription;
} if(! mqtt.ping()) { // Function to connect and reconnect as necessary to the MQTT server. // Stop if already connected. Serial.print("Connecting to MQTT... "); uint8_t retries = 3; |
I am using the AzureIoTHub simplesample_http. It works perfectly with 2.2, but upon grading to 2.3 I get this experience. I can connect to my router (reports assigned an IP address), but it keeps looping as though it failed and spews cryptic debugging errors. |
I have same problem with it , my connection get lost sometimes but module try to reconnect to Access point , and this make me problem when using the websocket |
@RogerSchaefer @zfields since this is a third party library, best we can do is help you make sense of "cryptic debugging errors" (whatever that may mean). Please feel free to open an issue, and provide the exact sketch you are running, settings you have in IDE tools menu, and full serial output. Thanks. |
Hello @igrr Roger |
Thanks for the logs, I was able to reproduce this with 2.3.0. Apparently, with SDK 1.5.3, if you call WiFi.begin by the time WiFi connection is already established, WiFi connection state machine enters some weird state. SDK function This was resolved in SDK 1.5.4, which is available in current git version of ESP8266 core. As a workaround, you can replace if (WiFi.status() != WL_CONNECTED) {
WiFi.begin(ssid, password);
} or with WiFi.persistent(false);
WiFi.mode(WIFI_OFF); // this is a temporary line, to be removed after SDK update to 1.5.4
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password); I will consider releasing 2.3.1 with a workaround for this issue in a couple of days. |
I fact the same problem. But work fine on NodeMCU1.0 (ESP-12E Module) ***** Resullt on ESP-01 // connected with belkin.a57, channel 6 |
@SupotSaeEa doesn't look like the same issue to me, because there are reconnect attempts visible in the log. Please check that you are setting correct flash size when compiling for you ESP-01 module. Usually they have smaller flash size than NodeMCU (512k or 1M). |
@igrr I add WiFi.setOutputPower(0); ESP-01 is work on 2.3.0. |
@SupotSaeEa's workaround seems to fix the issue for the ESP03 as well.
I can also confirm the settings are correctly set on the IDE for the module, checked every time I compiled. I tried checking with the older versions (2.0.0 - 2.2.0) but apparently I can't compile with them. Keeps throwing the following:
I'd like to reiterate that it works perfectly fine with the 2.3.0 package, just needs the workaround mentioned. |
I have the same problem on ESP-12 Lolin (Arduino 1.6.8). Reset ESP-12 , WiFI.begin() and WiFi.status() != WL_CONNECTED waits forever. Only repower the WIFI router help me. This solves the problem fine.
Thanks iggr. |
This may or may not be the same bug, but I'm using the Arduino IDE, and an Adafruit Huzzah, and the sketch I have works fine (Wifi.begin works fine and connects), until I upgrade the board from 2.1.0 to either 2.2.0 or 2.3.0 - in both cases, it no longer connects. Also, neither of the two fixes (output power to zero, nor mode to WIFI_OFF) as shown above works (but maybe they only work when using lua?). I haven't used the lua system, so for the moment this is only so helpful, but wanted to see if this sounds like the same bug, or a different bug, before I get too far. Thanks! |
I still confirm on solution to set output power to zero. Especially on Supot Sae-Ea 2016-10-08 8:54 GMT+07:00 CapnNemo [email protected]:
|
Just to chime in with my own observations... I have been getting this bug also. Sometimes it is random, but happens the first time I try connecting a new ESP module 100% of the time with my sketch. If I upload the wificlientbasic sketch and it connects I can then upload my own sketch and it can then connect to my AP. I also find I cannot connect if I had just previously put the ESP module into AP mode. So then I have to do the "reset" as I just described. Edit: tried the suggestions above and did not work:
Debug spits out chg_A2:-40 during attempts to connect. |
i had that problem too !!!
|
I had the same problem...It works fine to me: WiFi.mode(WIFI_OFF); //workaround |
If you don't want to loose connection of the ESP8266 AP, you can use:
Works with NodeMCU 1.0 and esp8266 v2.4 |
I will confirm that the bug exists for me as well on a NodeMCU 1.0, using the Arduino IDE with the esp8266 board library installed. I used this workaround suggested by @igrr and it is working now:
|
I've had the same intermittent problem with several NodeMCU v0.9 and v1.0 units. This code fixed it for me. Thanks to all that contribute!
|
I had a issue where, when ESP is assigned static IP from the router, it would connect to AP but fail to obtain IP. The issue was persistent in lwIP v2.0 Higher Bandwidth and Low Memory. |
@luffykesh This is a bug in 2.4.1 fixed in latest git version. |
@d-a-v Thank you. |
Beeing more specific, in STA mode, getting address by DHCP server (no static IP address in the sketch), you are observing twice more delay with lwip-v2 than with lwip-v1.4 ? |
Yes. |
@d-a-v |
@luffykesh |
Hi alltogether, Both refuse to connect to my router. I already flashed them a while ago, but this won't work any more.
I also tested some sketches from here and to setPowerOutput to 0. Nothing helped. My DebugOutput:
I changed between Wifi V1.4, V2 low mem and high band. Nothing... Any further ideas? Thanks, Update: |
Possibly you need to turn WiFi back on again?
But this thread is mostly about being connected, then occasionally seeing
your ESP disconnect after an arbitrary time.
…On Sun, Jun 24, 2018, 9:47 AM fabian727 ***@***.***> wrote:
Hi alltogether,
is there already an official bug fix? I encounter connection problems too.
I have the WEMOS D1 mini (with ESP8266MOD (so I think also called ESP12E))
and a WEMOS NodeMcu V3 of LoLin.
Both refuse to connect to my router. I already flashed them a while ago,
but this won't work any more.
My test-sketch at the moment
`#include <ESP8266WiFi.h>
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.mode(WIFI_OFF);
delay(2000);
WiFi.mode(WIFI_AP_STA);
WiFi.hostname("DEBUG");
while (WiFi.status() != WL_CONNECTED) {
WiFi.begin("WLAN_SSID",WLAN_PWD");
delay(5000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Print the IP address
Serial.print("My IP: ");
Serial.println(WiFi.localIP());
delay(500);
}
void loop() {
delay(5000);
}
`
I also tested some sketches from here and to setPowerOutput to 0. Nothing
helped.
My DebugOutput:
done state: 0 -> 2 (b0) ..state: 2 -> 0 (2) reconnect ......scandone
state: 0 -> 2 (b0) ..state: 2 -> 0 (2) reconnect ......scandone state: 0 ->
2 (b0) ..state: 2 -> 0 (2) reconnect .....scandone state: 0 -> 2 (b0) . and
so on
I changed between Wifi V1.4, V2 low mem and high band. Nothing...
Any further ideas?
Thanks,
Fabian
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2186 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AVpLPwbr0prMgIbNdWk3tqbbHM_gvjAtks5t_6aOgaJpZM4I9d2q>
.
|
the arbitrary time is between 0 and 0.1 ms I would say, or in other words: instantly. I got it working: it seems the WiFi module does not support WPA. I changed my security from WPA & WPA2 to only WPA2. Now it works. I think there is a big bug in the lib |
I am dealing with this issue right now and i have applied to code the given solutions. So far, i tested my system under a 8W fan load, i made POST request instantly to cause the system drop from wifi because of high current consumption and it did. Then i coded esp to re-estabilish wifi connection . I tested the system for 50 times to drop it and re-estabilish, as result at the 51.th of the trial it did not re-estabilish the connection ( i have waited 15 min to be re-connected ) but it did not. So far this is the temporarly best solution. Moreoever, if there are permanent solution for this problem, could you share please ? Thanks. |
@mmaxus35 Please try latest master. Yesterday's fixes were about WiFi disconnection and reconnection. |
as already stated I changed from WPA & WPA2 to only WPA2. This module with this flashed code worked. Now nothing works. I had to shut off and on again my router and reconfigure many devices to work again... seems to be only a lucky solution |
@d-a-v , how can I use this source code to upload in my board? I got the master branch, but I don´t know how to upload this into my board. |
@mmaxus35 I don't know the status of PlatformIO. The fixes mentioned above are very recent and are for the arduino core with lwIP-v2. @fabian27 please open a new issue and fill the issue template with all details you can. @TobiNorris Using the git master branch (all documentation's steps must be followed) or downloading the arduino core through the board manager result in the same IDE and tools. Press the Arduino IDE upload button. To all, this thread #2186 is an old issue, about an old version of the core, fixed, solved and closed. Your issues are unrelated with the OP. Please open new issues with your specific problems. edit: Followup to: WiFi cannot connect until a power cycle. #5527 |
This is still an issue in 2.5.0. Some device of mine got into a weird mode and was crashing after WiFi.begin or when using .disconnect(). I resolved it by using the following sequence (I wanted mode to be persistent, so the extra persistent commands):
|
i agree...i'm on 2.5.0 as well...but i think i saw this problem this morning....when my thermometer stopped delivering temperature measurements...event if it's been working for more than a month without problems. (wemos d1 mini running on battery) |
I was the newest addition to this issue.....after reading thru this post below is what has worked for me, my problem was more with "WiFi.status() " in getting to know if wifi was connected before switching to AP mode , the prevailing while loop with condition " (WiFi.waitForConnectResult() != WL_CONNECTED)" used to block for ever if your defined SSID was not available and would never get past it to switch to AP mode, I finally used the temp status WiFi.status() == WL_IDLE_STATUS to get past this issue:
|
If you use Arduino |
Installed the new 2.3.0 today and found that a sketch I have used for a long time will no longer cause the ESP8266 to connect with my WiFi
I reverted to version 2.2.0 and the sketch works fine.
ESP8266WiFi was the only ESP8266 include in the sketch
Roger
The text was updated successfully, but these errors were encountered: