-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifi_setup.py
30 lines (24 loc) · 891 Bytes
/
wifi_setup.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
import network
from time import ticks_ms, ticks_diff
try :
import _secrets
except ImportError :
print( "You need to create the _secrets.py file, see the _secrets.py.template file." )
raise SystemExit( "Missing the _secret.py file." )
wifi = network.WLAN( network.STA_IF )
def start_wifi():
try:
print( "Connecting to WiFi..." )
wifi.active( True )
wifi.connect( _secrets.WIFI_SSID, _secrets.WIFI_PASS )
start_tick = ticks_ms() # get millisecond counter
while not wifi.isconnected() :
waitTime = ticks_diff( ticks_ms(), start_tick)
if waitTime > 5000:
break
print( 'IP:', wifi.ifconfig()[0] )
except:
network.WLAN(network.STA_IF).disconnect()
raise
def stop_wifi() :
network.WLAN( network.STA_IF ).disconnect()