-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.lua
55 lines (51 loc) · 1.62 KB
/
setup.lua
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
-- file: setup.lua
local module = {}
local function wifi_wait_ip()
if wifi.sta.getip()== nil then
print("IP unavailable, Waiting...")
else
tmr.stop(1)
print("\n====================================")
print("ESP8266 mode is: " .. wifi.getmode())
print("MAC address is: " .. wifi.ap.getmac())
print("IP is " .. wifi.sta.getip())
print("====================================")
app.start()
end
end
local function wifi_start(list_aps)
if list_aps then
local found = false
for _, station_cfg in pairs(config.WIFI) do
for key,value in pairs(list_aps) do
if station_cfg.ssid == key then
wifi.setmode(wifi.STATION);
wifi.sta.config(station_cfg)
wifi.sta.connect()
print("Connecting to " .. key .. " ...")
found = true
--config.SSID = nil -- can save memory
tmr.alarm(1, 2500, 1, wifi_wait_ip)
end
end
end
if not found then
print("Error: Failed to connect to WIFI, no matching config! Found these networks:")
for key,value in pairs(list_aps) do
print(" - " .. key)
end
print("I have configuration for these:")
for _, station_cfg in pairs(config.WIFI) do
print(" - " .. station_cfg.ssid)
end
end
else
print("Error getting AP list")
end
end
function module.start()
print("Configuring Wifi ...")
wifi.setmode(wifi.STATION);
wifi.sta.getap(wifi_start)
end
return module