]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_core/commitdiff
nwfnet-go: behavioral changes
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 12 Aug 2018 11:06:03 +0000 (12:06 +0100)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 12 Aug 2018 11:06:03 +0000 (12:06 +0100)
don't persist changes
don't remove primary configuration file
don't configure softap, since we don't really support it

net/nwfnet-go.lua

index 7d4f201eeb6d2fae9b1421e3fd10e7fddfc3799e..5f154cc5fa44b7620e7289ec2eca8ab7a7309995 100644 (file)
@@ -8,24 +8,31 @@ 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)
 
--- One-shot configuration options; useful to change many things at once
--- at the next boot; all of these options are persisted by the ESP
+-- Connection configuration options
+--
+-- While these things could be persisted by the ESP, it's probably simpler to
+-- keep them in a file instead.
 if file.open("nwfnet.conf","r") then
   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({['ssid'] = essid, ['pwd'] = pw, save=true}) end
+    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})
+    end
 
     if conf["ap"] ~= nil then pcall(wifi.ap.config,conf["ap"]) end
+    -- XXX Don't really support softap yet, so...
+    -- local ccok = false
+    -- if conf["cc"] ~= nil then ccok = pcall(wifi.setcountry,conf["cc"]) end
 
     local modestr = conf["wifi_mode"]
-    if     modestr == "station"   then wifi.setmode(wifi.STATION)
-    elseif modestr == "softap"    then wifi.setmode(wifi.SOFTAP)
-    elseif modestr == "stationap" then wifi.setmode(wifi.STATIONAP)
-    else                               wifi.setmode(wifi.STATION)
+    if     modestr == "station"         then wifi.setmode(wifi.STATION)
+    -- XXX Don't really support softap yet, so...
+    -- elseif modestr == "softap" and ccok then wifi.setmode(wifi.SOFTAP)
+    elseif modestr == "stationap"       then wifi.setmode(wifi.STATIONAP)
+    else                                     wifi.setmode(wifi.STATION)
     end
 
-    if not conf["keepfile"] then file.remove("nwfnet.conf") end
    else print("nwfnet.conf malformed")
   end
   file.close()