espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.61k stars 7.41k forks source link

Wifi not connected to the esp32 module. #2144

Closed gaurav0190 closed 4 years ago

gaurav0190 commented 5 years ago

[D][WiFiGeneric.cpp:345] _eventCallback(): Event: 5 - STA_DISCONNECTED [W][WiFiGeneric.cpp:360] _eventCallback(): Reason: 2 - AUTH_EXPIRE [D][WiFiGeneric.cpp:345] _eventCallback(): Event: 0 - WIFI_READY [D][WiFiGeneric.cpp:345] _eventCallback(): Event: 2 - STA_START [D][WiFiGeneric.cpp:345] _eventCallback(): Event: 2 - STA_START [D][WiFiGeneric.cpp:345] _eventCallback(): Event: 5 - STA_DISCONNECTED [W][WiFiGeneric.cpp:360] _eventCallback(): Reason: 2 - AUTH_EXPIRE [D][WiFiGeneric.cpp:345] _eventCallback(): Event: 0 - WIFI_READY [D][WiFiGeneric.cpp:345] _eventCallback(): Event: 2 - STA_START [D][WiFiGeneric.cpp:345] _eventCallback(): Event: 2 - STA_START [D][WiFiGeneric.cpp:345] _eventCallback(): Event: 5 - STA_DISCONNECTED [W][WiFiGeneric.cpp:360] _eventCallback(): Reason: 2 - AUTH_EXPIRE [D][WiFiGeneric.cpp:345] _eventCallback(): Event: 0 - WIFI_READY [D][WiFiGeneric.cpp:345] _eventCallback(): Event: 2 - STA_START

Originally posted by @panther1 in https://github.com/espressif/arduino-esp32/issues/1829#issuecomment-417990979

gaurav0190 commented 5 years ago

I also have same issue when i dump the simple WiFi server code example to esp32 but it stuck to connect to the mobile hotspot. when i scan wifi network via the board , it shows the mobile wifi. please help me

arizzi commented 5 years ago

same here

lbernstone commented 5 years ago

1) Add WiFi.disconnect() at the beginning of setup() 2) Run python esptool.py erase_flash from the command line. This will wipe all code from the device (including the nvs partition). 3) Follow the instructions for posting an issue at ISSUE_TEMPLATE

me-no-dev commented 5 years ago

please try latest master. I just pushed a possible fix. please report if all is good

arizzi commented 5 years ago

I solved (independently of any master fix) it was a router problem solved rebooting it (while most of other devices were connecting to it with no problems I noticed one laptop was also not able to connect anymore hence I suspected the router)

thehellmaker commented 5 years ago

Guys, Thanks for keeping it open. It looks like I am facing same issue with some access points

Where does this happen?

  1. Happens on my phone Hotspot (One Plus 6, OxygenOS Version: 9.0.4, Build Number: A6000_22_190123)
  2. It doesn't happen on my Wifi router though. It happens only on specific access points

Here is the test scenario and how to reproduct

  1. Connect to Access Point
  2. Reset the module right after it connects to the access point (Not I am using WiFi.disconnect(true) before Wifi.begin())
  3. When it comes back up it goes into infinite AUTH_EXPIRE loop No amount of resetting the module helps the only thing that helps is closing doing the hotspot and bringing it back up. Its also shown in logs below that it connected only after NO_AP_FOUND event where I turn my hotspot off.

Here are the logs:

[I][Test_Wifi.cpp:134] connectToStoredAP(): Connecting to stored credentials ***********
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 0

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 4 - STA_CONNECTED
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 4

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 7 - **STA_GOT_IP**
[D][WiFiGeneric.cpp:385] _eventCallback(): STA IP: 192.168.43.40, MASK: 255.255.255.0, GW: 192.168.43.233
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 7

[D][Test_Wifi.cpp:109] WiFiEvent(): WiFi connected. IP address: 192.168.43.40
�x␌␎␃���[I][Test_Wifi.cpp:134] connectToStoredAP(): Connecting to stored credentials ***********
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 0

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 0

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:357] _eventCallback(): Reason: 2 - AUTH_EXPIRE
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 5

[D][Test_Wifi.cpp:113] WiFiEvent(): WiFi lost connection
[I][Test_Wifi.cpp:134] connectToStoredAP(): Connecting to stored credentials ***********
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 0

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:357] _eventCallback(): Reason: 2 - AUTH_EXPIRE
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 5

[D][Test_Wifi.cpp:113] WiFiEvent(): WiFi lost connection
[I][Test_Wifi.cpp:134] connectToStoredAP(): Connecting to stored credentials ***********
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 0

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:357] _eventCallback(): Reason: 2 - AUTH_EXPIRE
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 5

[D][Test_Wifi.cpp:113] WiFiEvent(): WiFi lost connection
[I][Test_Wifi.cpp:134] connectToStoredAP(): Connecting to stored credentials ***********
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 0

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:357] _eventCallback(): Reason: 4 - ASSOC_EXPIRE
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 5

[D][Test_Wifi.cpp:113] WiFiEvent(): WiFi lost connection
[I][Test_Wifi.cpp:134] connectToStoredAP(): Connecting to stored credentials ***********
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 0

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 5 - STA_DISCONNECTED
[W][WiFiGeneric.cpp:357] _eventCallback(): Reason: 201 - NO_AP_FOUND
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 5

[D][Test_Wifi.cpp:113] WiFiEvent(): WiFi lost connection
[I][Test_Wifi.cpp:134] connectToStoredAP(): Connecting to stored credentials ***********
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 2

[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 0

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 4 - STA_CONNECTED
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 4

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:385] _eventCallback(): STA IP: 192.168.43.40, MASK: 255.255.255.0, GW: 192.168.43.180
[D][Test_Wifi.cpp:106] WiFiEvent(): [WiFi-event] event: 7

[D][Test_Wifi.cpp:109] WiFiEvent(): WiFi connected. IP address: 192.168.43.40

Also I have gone through pretty much all issues ASSOC_EXPIRE and AUTH_EXPIRE. None help this https://github.com/espressif/arduino-esp32/issues/653 https://github.com/espressif/esp-idf/issues/738

SviFi commented 5 years ago

I have exactly the same issue as @thehellmaker describes. It does not connect to some hotspots, with infinite auth expire loop. And exactly the same thing, if I restart the hotspot - all of the sudden it connects. Actually, it happened to completely different wifi networks similar way. I need a solution ASAP.

@me-no-dev did you say you made some fixes that could be downloaded? Is it a new version of WiFi.h module? Where is it and how to update it? I am willing to test and report if it works. Thank you!

sansillusion commented 5 years ago

I had the same symptoms at a friend's place. Turns out his router default DHCP settings permitted only 10 devices at the same time.

asetyde commented 5 years ago

I've this problems after some time, lease time i think is problem, you can test with static address

kuoyaoming93 commented 5 years ago

I have the same problem. I can scan the ssid, but cant connect. I have to get closer to the AP to connect...

SviFi commented 5 years ago

I had a similar issue. What helped: I updated the Arduino's ESP32 in board manager to version 1.0.2 and it fixed the WiFi module behavior! It appears like there was a bug in the previous one. The second thing that helped in my case was a good quality USB cable. It first sounds crazy that USB cable can affect something like that, but indeed it does! In bad quality USB cables, the voltage drop is very high due to high resistance. This can cause the voltage to be too low for ESP32 and its power-hungry WiFi module to function. In such case, it would generate "Brownout detector triggered" warnings in the serial monitor and WiFi may be unable to connect. Replacing it with good quality USB cable immediately resolves this. It is not only about the length (even though typically the shorter the better), but primarily about quality, I had even 3-meter quality cables behave better than 0.5-meter bad quality one. I hope this information helps!

Iron24fit commented 5 years ago

Still this same problem of AUTH_EXPIRE loop . I don't find a reliable way to face it :(. Even with no password router ... :/

asetyde commented 5 years ago

This issue is showed from many users also in some our devices not all , 5% on all. But I can't find any solution or bug alert on ESP , @me-no-dev

me-no-dev commented 5 years ago

there are some updates in the 3.2 branch of IDF. I will merge them and rerelease the libs.

kuoyaoming93 commented 5 years ago

My issue:

Solution: ESP32 Arduino 1.0.3 Pre-Release Thank you very much @me-no-dev

me-no-dev commented 5 years ago

Hey :D it fixed something. Could you all please test 1.0.3-rc1 from the development package manager link?

kuoyaoming93 commented 5 years ago

I test with 2 different ESP32:

asetyde commented 5 years ago

Yes also us seems some connection problems it resolves (sometimes with reboot), but we ve noticed about range is few with some AP, it's strange thing

kuoyaoming93 commented 5 years ago

@me-no-dev There is a new release in ESP-IDF (v3.0.8), could you please build for this version? I will test it and report if this new version fix this issue or not.

Thank you, YM Kuo

lbernstone commented 5 years ago

arduino-esp32 is currently on esp-idf 3.2. When either 3.2.1 or 3.3 is released, the idf will be updated.

a-c-sreedhar-reddy commented 5 years ago

hey @lbernstone @kuoyaoming93 3.2.2 is released.

kuoyaoming93 commented 5 years ago

I compiled the IDF v3.2.2 by myself and also the ESP-IDF Pre-release v3.3-rc. But this bug in wifi's range stil exists.

bsayiner commented 5 years ago

Is there any update about this bug?

nandra commented 5 years ago

I experienced same. Have 2 esp32 modules and sometimes after flash one or other cannot connect ot wifi (I have WiFi.disconnect(true) and beginning of setup()). Is there some other workaround which can improve this @me-no-dev ? Thanks.

angus-grant commented 5 years ago

I'm getting the same problem on Netgear CG3100D-2 router and an older Apple AirPort Express.

I have tried flashing my current ESP32, bought a new device and got same problem straight away, etc.

Any help on this? It's really holding up a project I wanted to release end of last month.

Here is the end of the logs when trying to get ESP32 to connect to my wireless network

10:52:55.630 -> [W][WiFiGeneric.cpp:353] _eventCallback(): Reason: 2 - AUTH_EXPIRE 10:52:57.719 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 5 - STA_DISCONNECTED 10:52:57.719 -> [W][WiFiGeneric.cpp:353] _eventCallback(): Reason: 201 - NO_AP_FOUND 10:52:59.629 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 5 - STA_DISCONNECTED 10:52:59.629 -> [W][WiFiGeneric.cpp:353] _eventCallback(): Reason: 201 - NO_AP_FOUND 10:53:01.743 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 5 - STA_DISCONNECTED 10:53:01.743 -> [W][WiFiGeneric.cpp:353] _eventCallback(): Reason: 201 - NO_AP_FOUND 10:53:03.821 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 5 - STA_DISCONNECTED 10:53:03.856 -> [W][WiFiGeneric.cpp:353] _eventCallback(): Reason: 201 - NO_AP_FOUND 10:53:06.794 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 5 - STA_DISCONNECTED 10:53:06.794 -> [W][WiFiGeneric.cpp:353] _eventCallback(): Reason: 2 - AUTH_EXPIRE 10:53:07.611 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 5 - STA_DISCONNECTED 10:53:07.644 -> [W][WiFiGeneric.cpp:353] _eventCallback(): Reason: 202 - AUTH_FAIL 10:53:26.574 -> [D][WiFiGeneric.cpp:337] _eventCallback(): Event: 17 - AP_STAIPASSIGNED

Is there any more debug info I can add?

angus-grant commented 5 years ago

None of that stuff worked. I searched for so long across so many resources.

I ended up digging around in the ESP code base and happened upon this little nugget

ESP_ERROR_CHECK(nvs_flash_erase()); nvs_flash_init();

This seems to have cleared my "AUTH_EXPIRE" credentials and got my WiFi working again. One caution is that it clears everything in flash. So if you are using preferences library, etc, it all gets wiped.

michelpa commented 5 years ago

Hello,

I'm sorry, i do not understand your last message. Can you explain a little further please? Thanks

angus-grant commented 5 years ago

I was experiencing the AUTH_EXPIRE problem when trying to re-connect to my WiFi. Nothing had changed, the ESP had been working for a month or so. All of a sudden, it refused to re-connect to the same WiFi. I don't really know what was causing the AUTH_EXPIRE exception, but perhaps an expired DHCP lease not being released, or something along those lines.

I tried erasing the device as per instructions, but that did not work. I tried calling disconnect on the WiFi connection but it was never connected in the first place so couldn't disconnect, the AutoConnect library has no way to wipe all memorised WiFi networks. Or the std WiFi library

I found the code snippet above which did exactly what I wanted: erased the flash memory where the WiFi details were saved by the AutoConnect library. Basically all the WiFi management libraries all save their config in flash.

I forgot to mention above that you will also the the below include:

include "nvs_flash.h"

michelpa commented 5 years ago

Thank you for your response.

Unfortunately that did not work for me:

[WiFi-event] event: 5 Disconnected from WiFi access point WiFi lost connection. Reason: 2

Too sad!

angus-grant commented 5 years ago

Maybe try a

ESP.restart();

after the flash erase statement

bsayiner commented 5 years ago

Hello, I can't erase flash because other configuration settings exist. Do you have any workaround?

angus-grant commented 5 years ago

No, I dont. :(

I spent so long trying to find out a way wipe WiFi details from flash, directly read details from flash, etc.

The only solution I found was to wipe the entire flash area.

Hopefully someone else has a suggestion. There must be a way, I don't know what it is though.

lbernstone commented 5 years ago

WiFi.disconnect(false,true) will delete the saved WiFi connection info.

angus-grant commented 5 years ago

Does that work if you aren't connected to the WiFi network?

I didn't try with the true, false parameters, but WiFi.disconnect(); did nothing to help with my problem

thehellmaker commented 5 years ago

WiFi.disconnect(false,true) will delete the saved WiFi connection info.

Hi. This doesn't work. But I just updated esp32 platform version to 1.11.0 .Now it doesn't go into infinite loops. It does AUTH_EXPIRE for sometime and then AUTH_FAIL s and then connects. I had this issue until 1.9.0

angus-grant commented 5 years ago

I've only started ESP32 development, so forgive me if this is a simple question.

I can only see 1.0.4 as the latest version for the ESP32 development board option in Arduino IDE, and can see 1.0.4 as the latest release on the espressif GitHub page https://github.com/espressif/arduino-esp32/releases

Where are you getting version 1.11.0 from?

I assume you are not using the Arduino IDE, and there is some other platform you are using?

lbernstone commented 5 years ago

Platform.io v1.11.0

bsayiner commented 4 years ago

Does this issue be related to the ADC2 channel? Because Wifi drivers use ADC2 pins

thehellmaker commented 4 years ago

Update: the issue with hotspot was resolved with 1.11.0 platform io version. But I still have issues with with tp link TL WA 850 RE and goes into infinite AUTH_EXPIRE loop. After about 75 time of AUTH_EXPIRE it automatically reconnected.

Tonhom-Tools-Maker commented 4 years ago

I have this problem too.

I founded that this problem occurred when I use "Serial Monitor" of Arduino IDE 1.8.5. on Ubuntu. 16.04 LTS

My (temporary) solution is - - - - > use PuTTY instead Serial Monitor of Arduino IDE

Or

  1. Compile program and upload to ESP32 Board with Arduino IDE

  2. Close Arduino IDE

  3. Waiting my ESP32 Board Connect to WiFi Completed. (notify me with Built-ins LED)

  4. Open Arduino IDE

  5. Use Serial Monitor (of Arduino IDE) connect to my ESP32 Board

Tonhom-Tools-Maker commented 4 years ago

WiFi-ESP32-PuTTY

lele89m commented 4 years ago

yep! that work, using putty no problem for me

stale[bot] commented 4 years ago

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

stale[bot] commented 4 years ago

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

sohtamei commented 4 years ago

I faced this issue with CH340+ESP32 board (Wemos D1 R32), when USB-UART connection is OFF (RTS=H, DTR=H). I/F level of CH340 is 5V. When RTS=H & DTR=H, IO0 is 4.1V, EN is 4.1V. https://github.com/sohtamei/docs/blob/master/images/WenosD1R32_.jpg

When IO0 is 4.1V, the connection error which was reported on this thread occurs. I don't know why IO0=4.1V causes connection error.

lbernstone commented 4 years ago

Screenshot from 2020-07-13 10-33-19

Applying 4.1V power to your esp32 can permanently damage the device.

sohtamei commented 4 years ago

Hi lbernstone, Thanks !

When using "Wenos D1 R32" and "ESPDUINO32", there is a following workaround: Add 330 ohm to 3V3-RST and 3V3-IO0. image

dtmix commented 4 years ago

Hi, sohtamei and everybody - I stumbled upon the above solution after being at near wit's end on how to solve my ESP32 (its a Wemos D1 R32 dev board) WIFI issue. I am inexperienced in electronics, and would like to ask 2 questions:

  1. With the resistors used above, can I still make use of the 3V3 pin?
  2. Is there any other solution (e.g. firmware) that has resolved this todate? (I am trying to deploy my solution to a pilot environment and would prefer to avoid having resistors stick out like this, if possible to avoid)

Thanks so much!

sohtamei commented 4 years ago

Hi dtmix,

can I still make use of the 3V3 pin?

Yes, you can use 3V3 pin but you have to keep the register during wifi connection. To do it, you have to connect both the register and your device to one 3V3 pin.

(I am trying to deploy my solution to a pilot environment and would prefer to avoid having resistors stick out like this, if possible to avoid)

I also want it strongly, but I could not..

Could you try following solution ?

DSC05189 DSC05190

dtmix commented 4 years ago

Dear sohtamei,

THANK YOU so much for the prompt response!! Yes, I see your point! I ended up with similar idea of bending the resistor to the side eventually (but its not pretty) :-) I do wish there can be a firmware upgrade for this issue, but I guess not .. Nvm, will conceal this inside the box for final display.

Just to share info also, I think offloading sensor power requests to a breadboard with independent power supply can also make D1 R32 more stable ...

Again thanks and have a good day!!