Created
June 14, 2018 19:25
-
-
Save aderbas/c87aba9be95e2911f0fe667757044f50 to your computer and use it in GitHub Desktop.
Wemos D1 Mini init file wi-fi
This file contains hidden or 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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
: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}