Created
July 15, 2019 11:44
-
-
Save ildar/38019d0e01b85df531e1b0f272a6f3e4 to your computer and use it in GitHub Desktop.
NodeMCU init_draft.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- require "tmr" | |
rr_tmr = tmr.create() -- round-robin timer for wifi connect | |
stations = { | |
current = 0, | |
{ | |
ssid="AP1", | |
pwd="123456", | |
save=false | |
}, | |
{ | |
ssid="AP2", | |
pwd="123456", | |
save=false | |
}, | |
{ | |
ssid="AP3", | |
pwd="123456", | |
save=false | |
} | |
} | |
function rr_wifi(timer) | |
local ip = wifi.sta.getip() | |
if ip then --connected | |
rr_tmr:unregister() ; rr_tmr = nil | |
print("Connected to ".. stations[stations.current].ssid .."with IP ".. ip) | |
else | |
stations.current = stations.current + 1 | |
if type(stations[stations.current]) ~= "table" then | |
stations.current = 1 | |
end | |
print("Trying station " .. stations[stations.current].ssid) | |
wifi.sta.config(stations[stations.current]) | |
end | |
end | |
wifi.setmode(wifi.STATION) | |
rr_tmr:alarm(5000, tmr.ALARM_AUTO, rr_wifi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment