Skip to content

While NOT connected to WLAN #10557

Jan 23, 2023 · 3 comments · 1 reply
Discussion options

You must be logged in to vote

I think I got it right this time:

#IMPORT NECESSARY MODULES
import machine
from machine import Pin
import utime
import network

#ACTIVATE WIFI, CONNECT TO ROUTER
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.isconnected()
print("Connecting to router...")
wlan.connect('MYSSID', 'MYPASSWORD')

#CHECK IF CONNECTED TO WLAN
while not wlan.isconnected():
  pass# LOOP UNTIL CONNECTED

print("Connected")
print("Retrieving Network Configuration")
print("")
utime.sleep(1) # Give it a second to get an IP address (assigned by the router)
print (wlan.ifconfig())
#DO SOMETHING

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by marinehm
Comment options

You must be logged in to vote
1 reply
@marinehm
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants