MicroPython stuff

This commit is contained in:
2024-05-16 20:38:19 +03:00
parent a8e26be242
commit 60ba2c59e7
17 changed files with 478 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import time
import network
def connect(ssid: str, password: str) -> bool:
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.config(reconnects=2)
if not wlan.isconnected():
print('Scanning networks...')
wlan.scan()
print('Connecting to {0}...'.format(ssid))
# try:
wlan.connect(ssid, password)
while not wlan.isconnected():
status = wlan.status()
if status in (network.STAT_IDLE, network.STAT_WRONG_PASSWORD, network.STAT_NO_AP_FOUND):
print('\nConnection to "{0}" failed!'.format(ssid))
wlan.active(False)
return False
print('.', end='')
time.sleep(0.1)
print('\nConnection success!')
ifconfig = wlan.ifconfig()
print('IP: {0}'.format(ifconfig[0]))
return True
else:
print('Already connected!')
ifconfig = wlan.ifconfig()
print('IP: {0}'.format(ifconfig[0]))
return True