Skip to content

Instantly share code, notes, and snippets.

@aderbas
Created June 14, 2018 19:25
Show Gist options
  • Save aderbas/c87aba9be95e2911f0fe667757044f50 to your computer and use it in GitHub Desktop.
Save aderbas/c87aba9be95e2911f0fe667757044f50 to your computer and use it in GitHub Desktop.
Wemos D1 Mini init file wi-fi
local conf = nil
if file.open("config.txt") then
conf = file.read()
conf = sjson.decode(conf)
file.close()
end
local cfg = {
ip = conf.ip,
netmask = conf.netmask,
gateway = conf.gateway
}
--init.lua
wifi.sta.disconnect()
-- connect to WiFi access point
local station_cfg = {
ssid = conf.sid,
pwd = conf.pass,
save = true
}
wifi.setmode(wifi.STATION)
--wifi.sta.setip(cfg)
wifi.sta.config(station_cfg)
wifi.sta.connect()
print(station_cfg.ssid.." Status => "..wifi.STA_APNOTFOUND)
i=0
tmr.alarm(1, 1000, 1, function()
if (wifi.sta.status() ~= 5 and i < 10) then
print("Status:"..wifi.sta.status())
i = i + 1
else
tmr.stop(1)
if (wifi.sta.status() == 5) then
print("IP:"..wifi.sta.getip())
-- TODO HERE
dofile("anything.lua")
else
print("Status:"..wifi.sta.status())
end
end
end)
@aderbas
Copy link
Author

aderbas commented Jun 14, 2018

:3 config.txt file: {"ip": "xxx.xxx.xxx.xxx", "netmask":"255.255.255.0", "gateway":"xxx.xxx.xxx.xxx", "sid":"SID", "pass":"secret", "httpport":80}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment