-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect.lua
More file actions
48 lines (44 loc) · 975 Bytes
/
connect.lua
File metadata and controls
48 lines (44 loc) · 975 Bytes
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
local z = ...
local i = 0
local function setAP(a, f)
local n = {ip = "192.168.4.1", netmask = "255.255.255.0", gateway = "192.168.4.1"}
wifi.ap.config(a)
wifi.ap.setip(n)
a = nil
n = nil
f()
end
local function chk(m, a, f, t)
i = i + 1
local s = wifi.sta.status()
if i >= 30 then s = 42 end
local e = {[2]="Wrong password",[3]="No wireless network found",[4]="Connect fail",[42]="Connect timeout"}
ls = e[s]
e = nil
if s == 5 or ls then
t:unregister()
if s ~= 5 and m == wifi.STATION then
wifi.setmode(wifi.STATIONAP)
setAP(a, f)
else
f()
end
end
end
return function(f)
package.loaded[z] = nil
z = nil
local c = require("cfgFile")()
local m = c.sta and wifi.STATION or wifi.STATIONAP
local a = {}
a.ssid = c.ssid or "esp-devlab-setup"
a.pwd = c.pwd or "We1c0me!"
c = nil
wifi.setmode(m)
wifi.sta.autoconnect(1)
if m == wifi.STATION then
tmr.create():alarm(1000, 1, function(t) chk(m, a, f, t) end)
else
setAP(a, f)
end
end