1

im trying to connect my esp32 microcontroller via wifi. But it doesnt work. I followed the tutorial on https://docs.micropython.org/en/latest/esp32/quickref.html#networking step by step and watched a lot of youtubevideos.

my code looks like this:

import network
wlan = network.WLAN(network.STA_IF) # create station interface
wlan.active(True) 
print(wlan.scan())
wlan.connect('my_wlan_ssid', 'my_wlan_password')
print(wlan.isconnected())
print("Wlan is connected: ", wlan.isconnected())
print("My Wlan config: ", wlan.ifconfig())

here i add a picture from my command linde from the Thonny editor Command line from Thonny editor

The funny thing is, the webinterface from my router shows me the connection to the esp32 controller with his ip-address. I also tried it with a mobile-hotspot from my mobilephone. My mobilephone shows me the connection with the esp32, but the esp32 doesn't recognize the wlan connection So why is it so? Do i something wrong?

asked May 8, 2020 at 8:17

1 Answer 1

2

Seems like you are not letting the network actually make the connection.

wlan.connect('my_wlan_ssid', 'my_wlan_password')

takes time and as shown in the linked reference, wlan.isconnected() should be called in a while loop to ensure that it exits only if it is connected. (you could of-course do better management)

So how about you do this:

import network
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
 print('connecting to network...')
 sta_if.active(True)
 sta_if.connect('<essid>', '<password>')
 while not sta_if.isconnected():
 pass
 print('network config:', sta_if.ifconfig())

As per your own link

answered May 8, 2020 at 11:28
Sign up to request clarification or add additional context in comments.

2 Comments

Its working! Thank you so much, now i noticed my failure :)
@Carrot great to hear that it works. To show that this is the correct solution you should accept the answer that answered your question. This lets others know what worked for you. If it was a great answer you could even upvote it.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.