Skip to content

WiFi.status() always not connected. #2593

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
fabiosoft opened this issue Oct 10, 2016 · 21 comments
Closed

WiFi.status() always not connected. #2593

fabiosoft opened this issue Oct 10, 2016 · 21 comments
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.

Comments

@fabiosoft
Copy link

Basic Infos

Hardware

Hardware: ESP-01
Core Version: 2.3.0

Description

WiFi.status() always not connected. WL_CONNECTED is never set with version 2.3.0, instead with version 2.0.0 everything works ok.

It outputs a not connected state ...while surfing web!! How is it possible?

Settings in IDE

Module: Generic ESP8266 Module
Flash Size: 512k
CPU Frequency: 80Mhz
Flash Mode: dio
Flash Frequency: 40Mhz
Upload Using: SERIAL
Reset Method: ck

Sketch

#include <Arduino.h>

#include <ESP8266WiFi.h>

int status = WL_IDLE_STATUS;                     // the Wifi radio's status

void setup() {
  Serial.begin(57600);


  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { //<---- never changed! status never changes
    Serial.println("Attempting to connect to...");
    status = WiFi.begin("xxxx", "xxxx");

    // wait 10 seconds for connection:
    delay(1000);
  }

  // once you are connected :
  Serial.print("You're connected to the network");
}

void loop() {
  // check the network status connection once every 10 seconds:
  delay(1000);
  Serial.println(WiFi.status()); // <--- always NOT_CONNECTED status.
}
@WereCatf
Copy link
Contributor

No idea what's wrong, it works just fine on my ESPs.

@gilbertobueno
Copy link

Please, see issue 2186. Maybe it can help you. https://github.com/esp8266/Arduino/issues/2186

@KingModest
Copy link

Hi, am still having this issue, with AT commands module connects, but if I want to do this, status != WL_CONNECTED - the statement always return true

@savankoradia
Copy link

Same issue here. WiFi.status() returns 255. But still able to connect using AT command.

@mitsuhito
Copy link

I have same issue. my hardware is esp-wroom-02.
https://international.switch-science.com/catalog/2500/

@max5555
Copy link

max5555 commented Aug 21, 2017

A workaround is to replace
while ( status != WL_CONNECTED) {
with
while (WiFi.localIP().toString() == "0.0.0.0") {

@devyte
Copy link
Collaborator

devyte commented Oct 11, 2017

@fabiosoft is this issue still valid with latest git?

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Oct 11, 2017
@briskt
Copy link

briskt commented Jan 1, 2018

I just tested with the latest, and it still does the same for me. Sometimes (~30%) works, but usually returns WL_DISCONNECTED indefinitely.

@muthu29
Copy link

muthu29 commented Feb 3, 2018

Did anyone find the solution. I have the same problem always Wifi.status() is not connected and when I tried to print the Wifi.status() it returns value 0 for five times and a 6 once. I am wondering how this will by any chance give a String value of WL_CONNECTED :(

@briskt
Copy link

briskt commented Feb 4, 2018

@muthu29 the workaround by @max5555 is good. To answer your question about return value, WL_CONNECTED is an enum value that equates to 3. It's defined in wl_definitions.h:

typedef enum { WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library WL_IDLE_STATUS = 0, WL_NO_SSID_AVAIL = 1, WL_SCAN_COMPLETED = 2, WL_CONNECTED = 3, WL_CONNECT_FAILED = 4, WL_CONNECTION_LOST = 5, WL_DISCONNECTED = 6 } wl_status_t;

@devyte
Copy link
Collaborator

devyte commented Jul 12, 2018

This should be addressed in latest master.
@fabianoms @Fly4TheKing @muthu29 @KingModest could someone please retest?

@muthu29
Copy link

muthu29 commented Jul 12, 2018

For me it was a Typo in the SSID Password. It is working when I corrected it.

@devyte
Copy link
Collaborator

devyte commented Jul 13, 2018

Closing due to recent lwip glue fixes and WiFi::status() testing.

@slow-down
Copy link

How can it be, that it's still not fixed, even with 2.4.2 ... It's been more than 3 years. I had to use the workaround to fix it..

@ScientificNerd
Copy link

I tried the workaround, and it failed. So, I printed "WiFi.localIP().toString()" to the console, and to my amazement, it did not contain "0.0.0.0", but "(IP unset)", so I replaced the "0.0.0.0" with "(IP unset)" in the while statement, and it still didn't connect. Then I decided to check the router connections, and found that the IP had been issued, and the ESP was connected to the router.

At that point, I thought maybe the router was taking a bit longer to get everything done before the "while" timeout, so I added 15 seconds, and also decided to change the "while" statement to:

while (WiFi.localIP().toString() != IP) {
WiFi.begin(ssid, password) ;
// failed, retry
Serial.print(".");
delay(20000);
}
or
while (WiFi.localIP().toString() == "(IP unset)") {
WiFi.begin(ssid, password) ;
// failed, retry
Serial.print(".");
delay(20000);

Where "IP" was set as a global char* constant, as I had set the IP address for the ESP MAC in the router. Both were tested, and work.

I am using a Netgear WNDR3000-2, which takes its sweet time connecting. Since I need my ESP addresses to be fixed, I used the router to save the addresses rather than try to get the ESP's to request a fixed IP.

Now that this stumbling block is passed, I can finally move on to productive parts of my project.

@d-a-v
Copy link
Collaborator

d-a-v commented Sep 29, 2019

Please try and replace

while (WiFi.localIP().toString() == "(IP unset)") {

by

while (!WiFi.localIP().isSet()) {

Checking against a string is always worse when there are other means.

@ScientificNerd
Copy link

That works very well, Thanks! You are quite right about checking against strings, as it takes more program memory, as well as more time than checking for bool.

@ebrahimkarimi
Copy link

ebrahimkarimi commented Jun 1, 2020

for me, none of the above worked!!!
after digging deep i was able to debug it and find a solution that may work for everyone.
i just enabled debugging in Arduino IDE and used Serial to connect the esp8266-12e to my phone and debug it using USB Serial Terminal.
i found out there was messages like evt : <number> after a searched i realized there is WiFi events. so i found this. i realized connect event triggers after WiFi.begin(ssid,pwd) but StationGotIP event wont get triggered correctly:
Screenshot_20200601-230734_Serial USB Terminal
you can see that after connection established, event 0 triggered (event docs) but event 3 (EVENT_STAMODE_GOT_IP) didn't.
so i think the best and safe solution would be registering a EVENT_STAMODE_CONNECTED event.

some usable links:
Arduino ESP8266 - wifi evt: 3 and wifi evt: 7 meaning?

@esp8266 esp8266 locked and limited conversation to collaborators Apr 27, 2021
@esp8266 esp8266 deleted a comment from mazorvanunu Apr 27, 2021
@esp8266 esp8266 deleted a comment from mazorvanunu Apr 27, 2021
@esp8266 esp8266 deleted a comment from mazorvanunu Apr 27, 2021
@esp8266 esp8266 deleted a comment from mazorvanunu Apr 27, 2021
@esp8266 esp8266 deleted a comment from mazorvanunu Apr 27, 2021
@esp8266 esp8266 unlocked this conversation Apr 27, 2021
@Bighoneypot
Copy link
Contributor

Please, try with another SSID and Password, could be a problem with your router. Use Hotspot in your smartphone and try.
Leave the hotspot screen open and watch if your esp is connected on your hotspot.

@mazorvanunu
Copy link

come delete my comments "contributor" or maybe tell me to check up on my power cord. that will surely make a huge difference, i feel engulfed with your support. <3

@esp8266 esp8266 locked and limited conversation to collaborators Apr 27, 2021
@esp8266 esp8266 deleted a comment from mazorvanunu Apr 27, 2021
@esp8266 esp8266 deleted a comment from mazorvanunu Apr 27, 2021
@d-a-v
Copy link
Collaborator

d-a-v commented Apr 27, 2021

@mazorvanunu
This is a closed issue. Please open a new one with your data, don't forget to fill the issue template and provide an MCVE.
I deleted offending comments.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests