function self.mkclient(cf) -- construct a client with config from json file cf
local c, k, u, p, l
if file.open(cf) then
- local conf = cjson.decode(file.read())
+ local conf = cjson.decode(file.read() or "")
if type(conf) == "table" then
c = conf["clientid"]; k = conf["keepalive"]; u = conf["user"]; p = conf["pass"]; l = conf["clean"]
end
function self.connect(m,cf) -- make a connection with parameters from json file cf
local broker, port, secure
if file.open(cf) then
- local conf = cjson.decode(file.read())
+ local conf = cjson.decode(file.read() or "")
if type(conf) == "table" then
broker = conf["broker"]; port = conf["port"]; secure = conf["secure"]
end
-- One-shot configuration options; useful to change many things at once
-- at the next boot; all of these options are persisted by the ESP
if file.open("nwfnet.conf","r") then
- local conf = cjson.decode(file.read())
+ local conf = cjson.decode(file.read() or "")
if type(conf) == "table" then
local essid = conf["sta_essid"]; local pw = conf["sta_pw"]
if essid ~= nil and pw ~= nil then wifi.sta.config(essid,pw,0) end
end
if file.open("nwfnet.conf2","r") then
- local conf = cjson.decode(file.read())
+ local conf = cjson.decode(file.read() or "")
if type(conf) == "table" then
if conf["verify"] == 1 then print("Enabling certificate verification"); pcall(net.cert.verify,true) end
else print("nwfnet.conf2 malformed")
local nn = require "nwfnet"
if not server then
if file.open("nwfnet.conf2","r") then
- local conf = cjson.decode(file.read())
+ local conf = cjson.decode(file.read() or "")
if type(conf) == "table" then
if conf["sntp"] then print("Setting SNTP server"); server = conf["sntp"] end
else print("nwfnet.conf2 malformed")