44 lines
1012 B
Python
44 lines
1012 B
Python
# This file is executed on every boot (including wake-boot from deepsleep)
|
|
#import esp
|
|
#esp.osdebug(None)
|
|
#import webrepl
|
|
#webrepl.start()
|
|
|
|
import network
|
|
import machine
|
|
wlan = network.WLAN(network.STA_IF)
|
|
wlan.active(True)
|
|
binary_id = machine.unique_id()
|
|
hostname = 'timeular-{:02x}{:02x}{:02x}{:02x}'.format(binary_id[0],binary_id[1], binary_id[2], binary_id[3])
|
|
wlan.config(dhcp_hostname=hostname)
|
|
|
|
iphone = b'Hart\xe2\x80\x99s iPhone'
|
|
home = b"Hart's"
|
|
|
|
ff=wlan.scan()
|
|
connecting=true
|
|
for i in ff:
|
|
print(i)
|
|
|
|
def matches(nws, sid):
|
|
for i in nws:
|
|
if i[0] == sid:
|
|
return True
|
|
return False
|
|
|
|
if matches(ff,iphone):
|
|
print('connecting to iphone')
|
|
wlan.connect(iphone,'rg3t3jpht2aah')
|
|
elif matches(ff,home):
|
|
print('connecting to home')
|
|
wlan.connect(home,'D187wn644GeH')
|
|
else:
|
|
print('not connecting')
|
|
connecting = false
|
|
while connecting and not wlan.isconnected():
|
|
machine.idle()
|
|
print('WLAN connection succeeded')
|
|
|
|
import ntptime
|
|
ntptime.settime()
|