Can't connect WiFi after restart
Can't connect WiFi after restart
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
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
-
- Posts: 51
- Joined: Wed May 08, 2019 10:54 am
Re: Can't connect WiFi after restart
Hi ,
have you deployed the code on to the board. if not deploy the code and try again.
Thanks,
Raja
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
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
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
But didnt ttry set ip right in board code. I'll try then
Re: Can't connect WiFi after restart
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
But how to fix auto-obtaing the IP? My project depends on it.
Thanks
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Can't connect WiFi after restart
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
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')
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Can't connect WiFi after restart
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.
My programs all try to connect for 10 seconds and then reset the board if not successful.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Can't connect WiFi after restart
@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.
And i also tried it on different wifi Devices with same result.
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Can't connect WiFi after restart
You're not using a busy loop are you?
that can cause problems.
Code: Select all
while not sta_if.isconnected():
pass
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Can't connect WiFi after restart
@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 ..