Can't connect WiFi after restart

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
krekos
Posts: 9
Joined: Tue Oct 30, 2018 4:34 pm

Can't connect WiFi after restart

Post by krekos » Wed May 08, 2019 8:56 am

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

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: Can't connect WiFi after restart

Post by RajaRamesh » Wed May 08, 2019 11:04 am

Hi ,

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

Thanks,
Raja

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Can't connect WiFi after restart

Post by Roberthh » Wed May 08, 2019 11:21 am

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.

krekos
Posts: 9
Joined: Tue Oct 30, 2018 4:34 pm

Re: Can't connect WiFi after restart

Post by krekos » Wed May 08, 2019 11:25 am

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

krekos
Posts: 9
Joined: Tue Oct 30, 2018 4:34 pm

Re: Can't connect WiFi after restart

Post by krekos » Wed May 08, 2019 11:42 am

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

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Can't connect WiFi after restart

Post by pythoncoder » Thu May 09, 2019 6:15 am

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')
Peter Hinch
Index to my micropython libraries.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Can't connect WiFi after restart

Post by kevinkk525 » Thu May 09, 2019 7:20 am

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.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

krekos
Posts: 9
Joined: Tue Oct 30, 2018 4:34 pm

Re: Can't connect WiFi after restart

Post by krekos » Fri May 10, 2019 4:22 pm

@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.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Can't connect WiFi after restart

Post by kevinkk525 » Fri May 10, 2019 6:19 pm

You're not using a busy loop are you?

Code: Select all

while not sta_if.isconnected():
    pass
that can cause problems.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

krekos
Posts: 9
Joined: Tue Oct 30, 2018 4:34 pm

Re: Can't connect WiFi after restart

Post by krekos » Sat May 11, 2019 11:53 am

@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 ..

Post Reply