Page 1 of 3

Can't connect WiFi after restart

Posted: Wed May 08, 2019 8:56 am
by krekos
Hello i just encounter this problem. I succesfully connect to WiFi AP. But after i Reset Board i cannot connect to Wifi. It doesent matter if i reset board with button, machine.reset() or sys.exit(). Reflashing firmware doesn't help, but after some time not using the board I can coonect again until i reset.
I first thought i have bad board, but I have this behaviour on all of my ESP32 boards.

I using lastest FW from GIT with added uAsyncio. I also try prebuild FW 20181023 but it's still same.

i try to connect to different AP but this doesent help either.

All this i was trying by using simple code in ESP REPL:

import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('SSID', 'PASS')

In REPL terminal, I see mostly:
Reason: 2 - Auth_EXPIRE
Reason: 8 - ASSOC_LEAVE
Reason: 14 - 4WAY_HANDSHAKE_TIMEOUT

and nearly always
Reason: 201 - No AP Found


WiFi states when i'm trying to connect:
I (57236) wifi: state: init -> auth (b0)
I (57236) wifi: state: auth -> assoc (0)
I (57256) wifi: state: assoc -> run (10)
I (63356) wifi: state: run -> init (fc0)
I (63356) wifi: new:<10,0>, old:<10,0>, ap:<255,255>, sta:<10,0>, prof:1
I (63366) wifi: STA_DISCONNECTED, reason:15
I (65776) wifi: STA_DISCONNECTED, reason:201
no AP found


It's my first project in Micropython and first experience with ESP board. So i don't know if i try all possible options, so if somebody know what to do i'll be glad.

Thanks

Re: Can't connect WiFi after restart

Posted: Wed May 08, 2019 11:04 am
by RajaRamesh
Hi ,

have you deployed the code on to the board. if not deploy the code and try again.

Thanks,
Raja

Re: Can't connect WiFi after restart

Posted: Wed May 08, 2019 11:21 am
by Roberthh
That could be a problem with yuur access point and DHCP. I personally never had that issue, but have the habit of using static IP addresses. You get that by adding sta_if.ifconfig() with the appropriate parameters before the connect call. Of course you should know, which IP address is available for use.

Re: Can't connect WiFi after restart

Posted: Wed May 08, 2019 11:25 am
by krekos
I tried multiple AP's but none of them work. Also in DHCP settings in my AP i set static IP for ESP board.
But didnt ttry set ip right in board code. I'll try then

Re: Can't connect WiFi after restart

Posted: Wed May 08, 2019 11:42 am
by krekos
Setting IP in the code works. So i'm good for a while.

But how to fix auto-obtaing the IP? My project depends on it.
Thanks

Re: Can't connect WiFi after restart

Posted: Thu May 09, 2019 6:15 am
by pythoncoder
This is very odd and I've never seen this; it looks rather like some router/AP behaviour as if it hasn't acknowledged the fact of disconnection. I wonder if the behaviour can be replicated with other WiFi devices?

Perhaps a long shot but it might be worth repeating the attempt for a period - in this case 2 minutes

Code: Select all

import network
import time
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
for _ in range(10):
	sta_if.connect('SSID', 'PASS')
	time.sleep(1)
	if sta_if.isconnected():
	    print('Connected.')
	    break
	time.sleep(11)
else:
    print('Fail')

Re: Can't connect WiFi after restart

Posted: Thu May 09, 2019 7:20 am
by kevinkk525
I never encountered this either. However it does occasionally happen that my Esp32 can't connect to the wifi after a reset. Another resort however fixes that.
My programs all try to connect for 10 seconds and then reset the board if not successful.

Re: Can't connect WiFi after restart

Posted: Fri May 10, 2019 4:22 pm
by krekos
@pythoncoder I was trying this behaviour on similar code. I type SSID and Password manualy without For loop.

And i also tried it on different wifi Devices with same result.

Re: Can't connect WiFi after restart

Posted: Fri May 10, 2019 6:19 pm
by kevinkk525
You're not using a busy loop are you?

Code: Select all

while not sta_if.isconnected():
    pass
that can cause problems.

Re: Can't connect WiFi after restart

Posted: Sat May 11, 2019 11:53 am
by krekos
@kevinkk525 in my original code i have loop with sleep(0.1) until i succesfully connect to Wifi ... But when i start to debug the problem i strip the code to the basic ... So i wrote to the forum only the simplest code which i used to debug ..