-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboot.py
49 lines (42 loc) · 1.07 KB
/
boot.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
36
37
38
39
40
41
42
43
44
45
46
47
48
# boot.py
import config
import network
import utime
import ntptime
import gc
import machine
## ftp access
#from ftp import ftpserver
def do_connect():
sta_if = network.WLAN(network.STA_IF)
start = utime.time()
timed_out = False
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect(config.wifi_config["ssid"], config.wifi_config["password"])
while not sta_if.isconnected() and \
not timed_out:
if utime.time() - start >= 20:
timed_out = True
else:
pass
if sta_if.isconnected():
ntptime.settime()
print('network config:', sta_if.ifconfig())
else:
print('internet not available')
return timed_out
wdt = machine.WDT(timeout=config.app_config["watchdog"])
try:
wdt.feed()
timed_out = do_connect()
if timed_out:
utime.sleep_ms(10000)
machine.reset()
gc.collect()
except KeyboardInterrupt:
raise
except:
utime.sleep_ms(10000)
machine.reset()