]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_core/commitdiff
Remove nwfnet.conf2
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sat, 6 Jul 2019 20:44:39 +0000 (21:44 +0100)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 7 Jul 2019 00:40:59 +0000 (01:40 +0100)
Once upon a time, it was useful because wifi.sta.config() wrote its
changes to flash and we wanted to minimize wear and tear.  Those days
are long past.

Similarly, the utility of nwfnet-sntp is decreasing with time.  Let it
just default as upstream does now.

net/nwfnet-go.lua
net/nwfnet-sntp.lua

index 5f154cc5fa44b7620e7289ec2eca8ab7a7309995..b2f87b23f91c3a04e47ca5013bb895dac2dfb888 100644 (file)
@@ -8,6 +8,22 @@ wifi.eventmon.register(wifi.eventmon.STA_DHCP_TIMEOUT, function(_) (require "nwf
 wifi.eventmon.register(wifi.eventmon.STA_CONNECTED, function(t) (require "nwfnet"):runnet("wstaconn",t) end)
 wifi.eventmon.register(wifi.eventmon.STA_DISCONNECTED, function(t) (require "nwfnet"):runnet("wstadscn",t) end)
 
+-- do this before wifi because for some unknown reason it clobbers the
+-- configuration state.  I suspect that this is an SDK bug.
+if file.open("nwfnet.cert","r") then
+  local cert = ""
+  local chunk = file.read()
+  while chunk ~= nil do cert = cert..chunk; chunk = file.read() end
+  ok, res = pcall(net.cert.verify,cert)
+  file.close()
+  if ok then
+    print("Loaded cert from nwfnet.cert, which will now be removed.")
+    file.remove("nwfnet.cert")
+  else
+    print("Failed to load from nwfnet.cert", res)
+  end
+end
+
 -- Connection configuration options
 --
 -- While these things could be persisted by the ESP, it's probably simpler to
@@ -15,6 +31,7 @@ wifi.eventmon.register(wifi.eventmon.STA_DISCONNECTED, function(t) (require "nwf
 if file.open("nwfnet.conf","r") then
   local conf = sjson.decode(file.read() or "")
   if type(conf) == "table" then
+
     local essid, pw = conf["sta_essid"], conf["sta_pw"]
     if essid ~= nil and pw ~= nil then
       wifi.sta.config({['ssid'] = essid, ['pwd'] = pw, save=false})
@@ -33,33 +50,17 @@ if file.open("nwfnet.conf","r") then
     else                                     wifi.setmode(wifi.STATION)
     end
 
+    if conf["sntp"] then
+      (require "nwfnet").sntp = conf["sntp"]
+    end
+
+    if conf["tls_verify"] == 1 then
+      pcall(net.cert.verify,true)
+    end
+
    else print("nwfnet.conf malformed")
   end
   file.close()
 end
 -- must come after we've got our event callbacks registered, yeah?
 wifi.sta.connect()
-
-if file.open("nwfnet.cert","r") then
-  local cert = ""
-  local chunk = file.read()
-  while chunk ~= nil do cert = cert..chunk; chunk = file.read() end
-  ok, res = pcall(net.cert.verify,cert)
-  file.close()
-  if ok then
-    print("Loaded cert from nwfnet.cert; likely, you want to remove this file...")
-  else 
-    print("Failed to load from nwfnet.cert", res)
-  end
-end
-
-if file.open("nwfnet.conf2","r") then
-  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")
-  end
-end
index ee5b0c700593163eab7e3daa2409f821cf10f95d..11ef3ee4c41ae005a0180256aa1f00c28453598b 100644 (file)
@@ -1,21 +1,7 @@
 local function dosntp(server)
-  local nn = require "nwfnet"
-  if not server then
-    if file.open("nwfnet.conf2","r") then
-      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")
-  end end end
-  -- XXX Soon, in upstream, the NTP module will default to a ntp pool;
-  -- we should just let that happen here, when that happens!
-  local x, y
-  if not server then x, y, server = wifi.ap.getip() end
-  if not server then x, y, server = wifi.sta.getip() end
-  if not server then nn:runnet("sntperr", "No sntp server?") return end
-  sntp.sync(server,
-     function(sec,usec,server) rtctime.set(sec,usec); nn:runnet("sntpsync",sec,usec,server) end,
-     function(err) nn:runnet("sntperr",err) end
+  sntp.sync((require "nwfnet").sntp,
+     function(sec,usec,server) rtctime.set(sec,usec); (require"nwfnet"):runnet("sntpsync",sec,usec,server) end,
+     function(err) (require"nwfnet"):runnet("sntperr",err) end
   )
 end