-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.py
75 lines (57 loc) · 1.75 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
import network
import time
#from upysh import *
#import machine
mdns = network.mDNS()
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
# Hardcoded password in plaintext :-D
NETWORKS = {
"ssid": "password"
}
wifiConnected = False
def startAP():
wlanAP = network.WLAN(network.AP_IF)
wlanAP.active(True)
return wlanAP
cycle = 0
while not wlan.isconnected() and cycle < 10:
print("Scanning networks...")
scanResult = wlan.scan()
for i in range(len(scanResult)):
ssid = scanResult[i][0].decode()
if ssid in NETWORKS:
print("Trying to connect to ", ssid)
# SSID found in a table of known APs
wlan.connect(ssid, NETWORKS[ssid])
timeout = 0
while not wlan.isconnected():
timeout += 1
time.sleep(1)
print("Attempt ", timeout, " out of 10")
if (timeout >= 10):
print("Unable to connect to the WiFi")
break
wifiConnected = wlan.isconnected()
else:
print ("Record for SSID ", ssid, " not found, let's try next one")
cycle += 1
if wifiConnected:
print("Connected to the wifi")
print(wlan.ifconfig())
else:
print("Unable to connect to the WiFi, let's start own AP")
AP = startAP()
print(AP.ifconfig())
del(cycle)
del(ssid)
del(i)
del(wifiConnected)
mdns.start('mPy', 'MicroPython ESP32')
#ftp.start(user='YOUR_USERNAME', password='YOUR_PASSWORD')
#telnet.start(user='YOUR_USERNAME', password='YOUR_PASSWORD')
import webrepl
webrepl.start()