-- DEPEND: file?, gpio, node, rtctime?, tmr ; nwfnet, nwfnet-diag, nwfnet-go, telnetd
if rtctime then rtctime.set(0) end -- set time to 0 until someone corrects us
--- XXX much of this framework calls cjson as such; that should be fixed
-if not cjson then _G.cjson = sjson end
-
-- See if there's any early startup to do.
if file and file.exists("init-early.lua") then dofile("init-early.lua") end
--- DEPENDS: cjson, file, mqtt; nwfnet
+-- DEPENDS: file, mqtt, sjson; nwfnet
local nwfnet = require "nwfnet"
local self = {}
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() or "")
+ local conf = sjson.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() or "")
+ local conf = sjson.decode(file.read() or "")
if type(conf) == "table" then
broker = conf["broker"]; port = conf["port"]; secure = conf["secure"]
end
--- DEPENDS: cjson, file, mdns, net, rtctime, sntp, wifi; nwfnet, nwfnet-sntp
+-- DEPENDS: file, mdns, net, rtctime, sjson, sntp, wifi; nwfnet, nwfnet-sntp
wifi.eventmon.register(wifi.eventmon.STA_GOT_IP, function(t)
(require "nwfnet"):runnet("wstagoip",t)
if mdns then mdns.register(wifi.sta.gethostname()) 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() or "")
+ local conf = sjson.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() or "")
+ local conf = sjson.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() or "")
+ local conf = sjson.decode(file.read() or "")
if type(conf) == "table" then
if conf["sntp"] then server = conf["sntp"] end
else print("nwfnet.conf2 malformed")