23 lines
634 B
Python
23 lines
634 B
Python
|
import network
|
||
|
from credentials import *
|
||
|
# NET_SSID="xxx"
|
||
|
# NET_PASS="yyy"
|
||
|
|
||
|
class wifi:
|
||
|
def __init__(self):
|
||
|
self.if_ap = network.WLAN(network.AP_IF)
|
||
|
self.if_sta = network.WLAN(network.STA_IF)
|
||
|
|
||
|
def status(self):
|
||
|
return self.if_sta.isconnected()
|
||
|
|
||
|
def connect(self):
|
||
|
self.if_ap.active(False)
|
||
|
self.if_sta.active(True)
|
||
|
if not self.if_sta.isconnected():
|
||
|
print("connect: reconnecting...")
|
||
|
self.if_sta.connect(NET_SSID, NET_PASS)
|
||
|
while not self.if_sta.isconnected():
|
||
|
pass
|
||
|
print("network config: ", self.if_sta.ifconfig())
|