-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Wifi.status #119
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
hi kdschlosser I'm interested in the same thing. Any progress? |
github has a nice search:
|
that didn't exactly answer my question or statement. the problem is the ESP reboots because of not having a "connection" which is determined by the IP and an IP address is not a wifi connection, so there is no cause for the module to keep on boot cycling, there are other functions that the ESP is able to perform without actually having an IP Address. is there a way to have the ESP operate without an IP address? and to send DHCP requests until it receives one? |
you can move the WiFi waiting to the loop like this: void setup() {
Serial1.begin(921600);
delay(10);
// We start by connecting to a WiFi network
Serial1.println();
Serial1.println();
Serial1.print("Connecting to ");
Serial1.println(ssid);
WiFi.begin(ssid, password);
}
void loop() {
if(WiFi.status() != WL_CONNECTED) {
Serial1.println("[loop] no wifi");
delay(500);
} else {
Serial1.println("[loop] WiFi connected");
Serial1.print("[loop] IP address: ");
Serial1.println(WiFi.localIP());
delay(500);
}
}
but mixed mode (dhcp / static) is not possible. enum {
STATION_IDLE = 0,
STATION_CONNECTING,
STATION_WRONG_PASSWORD,
STATION_NO_AP_FOUND,
STATION_CONNECT_FAIL,
STATION_GOT_IP
}; so you have no change to see if you are connected but not get an answer from the DHCP. what you exactly mean by "reboots" normaly the ESP try to get an DHCP IP endless. |
it restarts, reboots like a computer, any time that W_CONNECTED returns false in any kind of a loop with it, sees it as an infinite loop so the ESP restarts i think. have put it in it's own function outside of loop and setup i have had it loop inside setup, have had it loop inside loop and use loop for the loop, it always resets the ESP. no matter what i do. it would have been nice to use it to jump to a different wifi netowrk (don't even know if that is possible) but that was the hope for it. |
if you need WiFi connection management for multiple APs you can use WiFiMulti a "loop" in setup is possible you only need to add a delay(0);
gives you more info about reboots/crash. |
the access point example in the arduino IDE should be fixed / updated. when connected all it does is spit out periods over console like nothings connected even when it is connected. |
I have the same problem as @tecan. The AP example only spits out dots.... WiFi.localIP() returns 0.0.0.0 so I cant start a webserver. |
I'm in the same situation of @wizard23 some help ? If i connect , ping to 192.168.4.1 work but only dots on serial. |
Is the softAP resetted after every attempt to connect to a router? I just happened to find a particular behavior on arduino core. My code
If I submit the ssid and wrong password, after around 6 seconds the ajax connection is aborted. Chrome shows net::ERR_CONNECTION_RESET.
Is there an internal function that resets/ restarts the softAP while waiting to connect to router? I tried the following tests.
And this behaviour is consistent, repeatable. So, it seems like when pwd is wrong and while trying to connect, somehow the softAP is reset after? |
the ESP need to switch to all channels for scanning and if its try to connect to some AP that Wifi channel of the softAP is changed. try to use a WiFi scanner app or tool and look for your soft AP, then you shut see the channel changes. |
I don't think your explanation of this is correct. I'm trying to do the same thing as @avarachanvc is doing, in fact my code looks very similar. Anyway. I ran "Acrylic Wifi" which is a wifi scanner for Windows and the ESP8266 always seems to be on Channel 1, where as my target network is on channel 9. But..., I can get an ajax response from the ESP8266 back to my PC (which is connected to the ESP8266 as an AP). This means that the ESP8266 is operating on both channel 1 and also channel 9. I think the issue is that @avarachanvc is calling things like wifi.disconnect() - although they are commented out in the code that is posted. I think calling WiFi.disconnect() or WiFi.mode(WIFI_STA); at any time near where you send back the response to the ajax, is seriously messing things up. I suspect the only way to be able to use WiFi.disconnect() is after a time delay, but this would need to be done on a timer callback I think rather than a delay, as delays are not good in this sort of system, as most things are asynchronous. Although I wrote my code the same way, I also suspect that doing this
is not a good idea either, I've noticed that Windows sporadically sends requests for a file named ncsi.txt - which from what I've read is a file that sits on a windows server and Microsoft use as a flag to indicate if you are really connected to the internet or not. I've not quite worked out what's going on (and I still may need to use WiFi.disconnect(), but I find if I deliberately send a wrong password. Then even if I resent the ajax request a while later, with the correct password, that the ESP8266 fails to connect to the AP. Anyway, I think there is more to this than something to do with the RF section of the chip Edit.. Just an additional thought, returning a response when connecting to an AP seem unreliable. I'm going to try sending a response straight await, ie just something like "OK", which I will probably ignore on the requesting page. But add another ajax based service e.g. /isconnected, and get the ESP8266 to return the result of As from what I've observed it was possible for both AP and STA to be operating at the same time (though I could be wrong and its getting to late here to try that idea) |
OK. As this is random, I don't know if other OSs do the same. Also, I do occasionally get disconnection errors from the ajax request. I wonder if there is a workaround for this at all. Wait a few secs for the client OS to notice the Soft AP has moved Then send an ajax request from the client to tell the ESP to connect to the AP ( which will now be on the same channel as the Soft AP) However, It looks like its highly dependent on which OS is connecting to the AP. |
there is a command may it work to move the AP before the connect. here is an example how to scan for APs in a async way: |
Thanks Actually, for some reason, scanning doesn't seem to drop the soft AP. I'm using an ajax request to do the scan, just using WiFi.scanNetworks(); I seem to have a very high success rate with this, and don't seem to have any problems on Windows or iOS with Wifi disconnection of an open ajax request. Re: wifi_station_disconnect As I have debug turned on, I noticed that if that the SDK kept trying to reconnect if the password etc was incorrect. So I had already tried calling Wifi.disconnect() which basically calls, wifi_station_disconnect(), however this didnt seem to help. I think the main problem is when the client OS connecting to the softAP decides to rescan. Also part of the problem could be the way that we are detecting connection. i.e it looks like the presumption with WiFi.begin() is that the correct username and password will always be supplied. I think I will investigate using wifi_station_set_reconnect_policy(false) to see if this improves things Edit. Using wifi_station_set_reconnect_policy(false) but this does not stop the random disconnection issue :-( |
I'm working on some code to detect different Wifi failures, and am trying to understand the best way to do this. From reading this thread, it seems that WiFi.status() == WL_CONNECTED will tell me "if I have an IP Address" ... but will that change if - for example - I turn off the AP? Or if I move out of range of the AP? I'll do more testing myself, but am very curious what the "recommended" way is to handle Wifi failures and re-connection attempts? Thanks! |
the latest version has a event callback for wifi changes. |
Nice! Thank you for the references! Just as an update of my own testing ...
Now I'll add these events into my code ... thanks again! |
@Links2004 is this new event callback in "stable" yet? |
no only straring |
I think I have the opposite problem of everyone else. I have not narrowed it down yet, but when the board is powered up, I'm getting a connection status of WL_CONNECTED before I configure the node. Because of that, the software attempts to disconnect first and then segfaults. Some how wifi_station_get_connect_status is returning STATION_GOT_IP before I call begin. Any suggestions? |
No complete sketch, basic info. |
Hi, I hope somebody to help me. Nothing is a correct way to confirm? |
@Anatoli113 like I said in the previous comment, look into the wifi event system. |
Hi, Connecting to SmartHome2 Anyone can help? |
P.S. Well it didn't last overnight, so I'll try the bottom approach.
P.S. I, also, found that in the BasicOTA example, it uses |
thank you, this worked for me as well |
not sure if this is a problem per say but the use of
WiFi.status() != WL_CONNECTED
is not a check to see if you are connected to the Wireless AP
it looks to see if it has an IP address
they are 2 completely different things.
maybe i am just misinterpreting the WL_CONNECTED but i would imagine that means Wireless LAN Connection
I have a server that is DHCP that server can go down and and not affect the AP connection. granted it can't talk to the Network. but I am trying to make a script that if the connection actually goes down it will reconnect. and if the server goes down it will just keep on broadcasting DHCP requests until it gets an IP
not actually have to reset the connection.
script is for redundancy. it's supposed to fire up other backup equipment if there is a problem. and then send me an e-mail and text message letting me know something's broke and what it is that's broken. I don't know if this is incorrect coding on my part or it's the coding in the IDE and how it deals with checking a connection. but an IP address is not a wifi connection.
if there is an alternate way someone please let me know. I have gone digging through the wificlient library and i am not seeming to be able to find what i am looking for.
I don't want this firing up equipment that doesn't need to be and not telling me what is exactly wrong.
thanks again for the assistance. and i do appoligize if this is my dumbass not reading the code correctly. lol
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: