Created
November 23, 2022 03:46
-
-
Save neosarchizo/bab85a5a41775e18963fce7f8e769cb4 to your computer and use it in GitHub Desktop.
MicroPython - RPi Pico W WiFi 사용하기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from network import WLAN, STA_IF | |
from time import sleep | |
SSID = 'devicemart' | |
PASSWORD = 'devicemart1' | |
wlan = WLAN(STA_IF) | |
wlan.active(True) | |
wlan.connect(SSID, PASSWORD) | |
max_wait = 10 | |
while max_wait > 0: | |
if wlan.status() < 0 or wlan.status() >= 3: | |
break | |
max_wait -= 1 | |
print('waiting for connection...') | |
sleep(1) | |
if wlan.status() != 3: | |
raise RuntimeError('network connection failed') | |
else: # wlan.status() == 3 | |
print('connected') | |
status = wlan.ifconfig() | |
print('ip = ' + status[0]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment