-
Notifications
You must be signed in to change notification settings - Fork 1
/
connect.py
38 lines (31 loc) · 958 Bytes
/
connect.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
import machine
import network
import time
import config
def start_ftp():
print('Starting FTP...')
network.ftp.start()
def start_ntp():
print('Syncing to NTP...')
rtc = machine.RTC()
rtc.ntp_sync(server='pool.ntp.org')
if not rtc.synced():
print(' waiting for time sync...', end='')
time.sleep(0.5)
while not rtc.synced():
print('.', end='')
time.sleep(0.5)
print('')
print('Time:', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
def connect_to_ap():
station = network.WLAN(network.STA_IF)
if not station.active():
station.active(True)
if not station.isconnected():
print('Connecting....')
station.connect(config.SSID, config.PASSWORD)
while not station.isconnected():
time.sleep(1)
print('.', end='')
print('')
print('ifconfig =', station.ifconfig())