-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathS50wifi.lua
47 lines (42 loc) · 1.32 KB
/
S50wifi.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
-- WiFi mode
-- One of: 1 = STATION, 2 = SOFTAP, 3 = STATIONAP, 4 = NULLMODE
print("WiFi Mode: ", wlanmode)
local function config_sta()
wifi.sta.on("connected", function() print("sta connected") end)
wifi.sta.on("got_ip", function(event, info) print("sta got ip "..info.ip) localstaip = info.ip end)
wifi.sta.config({ssid=sta_ssid, pwd=sta_pwd, auto=true}, true)
if (sta_hostname ~= nil and sta_hostname ~= '') then
wifi.sta.sethostname(sta_hostname)
end
end
local function config_ap(channel)
wifi.ap.on("start")
wifi.ap.on("sta_connected", function(event, info) print("Station connected: "..info.mac ) end)
wifi.ap.config({ssid=ap_ssid, pwd=ap_pwd})
wifi.ap.setip({ip=ap_ip, netmask=ap_netmask, gateway=ap_gateway, channel=channel, dns=ap_dns})
if (ap_hostname ~= nil and ap_hostname ~= '') then
wifi.ap.sethostname(ap_hostname)
end
end
if wlanmode == 1 then
wifi.mode(wifi.STATION, true)
end
if wlanmode == 2 then
wifi.mode(wifi.SOFTAP, true)
end
if wlanmode == 3 then
wifi.mode(wifi.STATIONAP, true)
end
wifi.start()
if wlanmode == 1 or wlanmode == 3 then
config_sta()
end
if wlanmode == 2 then
config_ap(ap_channel)
end
if wlanmode == 3 then
config_ap(nil)
end
uplinktimer = tmr.create()
uplinktimer:register(10000, tmr.ALARM_SINGLE, function() print("Starting NTP service") time.initntp() end)
uplinktimer:start()