-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwireless.lua
37 lines (27 loc) · 930 Bytes
/
wireless.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
-- file: wireless.lua
local module = {}
function module.is_ready()
return wifi.sta.status() == wifi.STA_GOTIP
end
function module.start(station_cfg)
-- register event monitors
-- connected
wifi.eventmon.register(wifi.eventmon.STA_CONNECTED,
function(T)
print("\n\tSTA - CONNECTED".."\n\tSSID: "..T.SSID.."\n\tBSSID: "..T.BSSID.."\n\tChannel: "..T.channel.."\n\tRSSI: "..wifi.sta.getrssi())
end)
-- disconnected
wifi.eventmon.register(wifi.eventmon.STA_DISCONNECTED,
function(T)
print("\n\tSTA - DISCONNECTED".."\n\tSSID: "..T.SSID.."\n\tBSSID: "..T.BSSID.."\n\tReason: "..T.reason)
end)
-- got IP
wifi.eventmon.register(wifi.eventmon.STA_GOT_IP,
function(T)
print("\n\tSTA - GOT IP".."\n\tStation IP: "..T.IP.."\n\tSubnet mask: "..T.netmask.."\n\tGateway IP: "..T.gateway)
end)
-- set mode and config
wifi.setmode(wifi.STATION)
wifi.sta.config(station_cfg)
end
return module