WiFi connection Question

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Ajaykrishna123
Posts: 1
Joined: Tue Apr 28, 2020 7:52 pm

WiFi connection Question

Post by Ajaykrishna123 » Tue Apr 28, 2020 7:54 pm

Hi, I have been trying to get my ESP 32 to connect to my local network using micropython. I found a lot of documentation online with sample code. All the examples use the following attached below. If the SSID or password is wrong, won't the while loop be stuck indefinitely? I see all examples with this implementation. How do I change the code so that the connection process stops after it gets a password incorrect error?

station = network.WLAN(network.STA_IF)
station.active(True)
station.connect(ssid, password)
while station.isconnected() == False:
pass

User avatar
jimmo
Posts: 1633
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: WiFi connection Question

Post by jimmo » Tue Apr 28, 2020 11:45 pm

Ajaykrishna123 wrote:
Tue Apr 28, 2020 7:54 pm
How do I change the code so that the connection process stops after it gets a password incorrect error?
You can use the status() method to find out whether the connection succeeded or not.

Please also see viewtopic.php?f=18&t=7942 -- there's a bug where you won't always see the reason for failure, but you will see that it did fail.

kellycurry
Posts: 1
Joined: Thu May 21, 2020 3:00 am

Re: WiFi connection Question

Post by kellycurry » Thu May 21, 2020 3:35 am

jimmo wrote:
Tue Apr 28, 2020 11:45 pm
Ajaykrishna123 wrote:
Tue Apr 28, 2020 7:54 pm
How do I change the code so that the connection process stops after it gets a password incorrect error?
You can use the status() method to find out whether the connection succeeded or not.

Please also see viewtopic.php?f=18&t=7942 -- there's a bug where you won't always see the reason for failure, but you will see that it did fail.
Thanks for your answer. It helped me a lot.

Post Reply