-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwifi.lua
48 lines (45 loc) · 1.53 KB
/
wifi.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
-- GESTION WIFI
-- Réalise la connection WIFI
-- quand établie, execute on_wifi_connected()
--TODO : supprimer ce module!
-- ou alors faire wifi.sta.clearconfig() et test si wifi.stat.ssid is in App.ssid
function wait_for_wifi_conn()
local wifi_alarm = tmr.create()
wifi_alarm:alarm (10000, tmr.ALARM_AUTO, function()
if wifi.sta.getip() == nil then
wifi.setmode(wifi.STATION)
local _SSID
local _PASSWORD
_SSID = App.net.ssid[WIFI_INDEX]
print_log ("Waiting for Wifi connection on " .. _SSID)
if (type(App.net.password)=='table') then
_PASSWORD = App.net.password[WIFI_INDEX]
else
_PASSWORD = App.net.password
end
wifi.sta.config({ssid = _SSID, pwd=_PASSWORD})
if (WIFI_INDEX < table.getn(App.net.ssid)) then
WIFI_INDEX = WIFI_INDEX + 1
else
WIFI_INDEX = 1
end
else
wifi_alarm:stop()
print_log ("The module MAC address is: " .. wifi.sta.getmac ( ))
local _ssid = wifi.sta.getconfig()
print_log ("Access point : " .. _ssid)
print_log ("Config done, IP is " .. wifi.sta.getip ( ))
if on_wifi_connected ~= nil then
on_wifi_connected()
end
end
end)
end
if (type(App.net.ssid)=='string') then App.net.ssid = {App.net.ssid} end
WIFI_INDEX = 1
wait_for_wifi_conn()
tmr.create():alarm(App.net.wifi_time_retry*60000,1,function()
if wifi.sta.getip() == nil then
wait_for_wifi_conn()
end
end)