-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWiFi.py
35 lines (29 loc) · 897 Bytes
/
WiFi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import network
import secrets
import time
try:
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
time.sleep_ms(100)
wlan.connect(secrets.SSID, secrets.PASSWORD)
assert wlan.isconnected() == True
except Exception as e:
raise e
class Networker:
def __init__(self):
self._connection = None
def establish_connection(self):
try:
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
time.sleep_ms(100)
wlan.connect(secrets.SSID, secrets.PASSWORD)
assert wlan.isconnected() == True
self._connection = wlan
except Exception as e:
raise e #"Unable to establish wifi connection!"
@property
def connection(self):
if self._connection is None:
self.establish_connection()
return self._connection