homecontrol-bh1750/wifi.py

23 lines
634 B
Python
Raw Permalink Normal View History

2019-11-03 14:56:56 +01:00
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())