Skip to content

Instantly share code, notes, and snippets.

@ildar
Created July 15, 2019 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ildar/38019d0e01b85df531e1b0f272a6f3e4 to your computer and use it in GitHub Desktop.
Save ildar/38019d0e01b85df531e1b0f272a6f3e4 to your computer and use it in GitHub Desktop.
NodeMCU init_draft.lua
-- 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