commit 1
This commit is contained in:
15
wifi.py
Normal file
15
wifi.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import network
|
||||
import time
|
||||
|
||||
def connect_wifi(ssid, password, hostname):
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
wlan.config(hostname=hostname)
|
||||
wlan.connect(ssid, password)
|
||||
|
||||
for _ in range(10):
|
||||
if wlan.isconnected():
|
||||
return wlan
|
||||
time.sleep(1)
|
||||
|
||||
raise RuntimeError("WiFi connection failed")
|
||||
Reference in New Issue
Block a user