From 37783f3f062ba203d643fecf8f1dacda5b0ff193 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 4 Oct 2013 16:29:53 +0200 Subject: [PATCH] Fixed boot wifi connection issues by adding sleep --- src/main.lua | 19 ++++++++++--------- src/network/netconfig.lua | 7 ++++--- src/network/wlanconfig.lua | 27 ++++++++++++++------------- src/rest/api/api_network.lua | 7 ++++++- src/script/wifibox_init | 2 ++ 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/main.lua b/src/main.lua index 144c8fb..8864e64 100644 --- a/src/main.lua +++ b/src/main.lua @@ -60,7 +60,7 @@ local function setupAutoWifiMode() break end end - + if connectWith then local rv,msg = netconf.associateSsid(connectWith) if rv then @@ -143,7 +143,7 @@ local function init(environment) end if dbgText ~= "" then dbgText = " (" .. dbgText .. " debugging enabled)" end - + log:info("===========================") log:info("Wifibox CGI handler started" .. dbgText) if (environment['REQUEST_METHOD'] == 'POST') then @@ -177,15 +177,16 @@ local function main(environment) log:info("running in signin mode") local ds = wifi.getDeviceState() + log:info(" ds.mode: "..util.dump(ds.mode)) if ds.mode == "sta" then - local rv,msg = Signin.signin() + log:info(" attempting signin") + local success,msg = Signin.signin() + if success then + log:info("Signin successful") + else + log:info("Signin failed: "..util.dump(msg)) + end end - - --[[if rv then - log:info("autowifi setup done (" .. msg .. ")") - else - log:error("autowifi setup failed (" .. msg .. ")") - end]]-- elseif rq:getRequestMethod() ~= 'CMDLINE' or confDefaults.DEBUG_API then -- log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "") -- .. "/" .. (rq:getRealApiFunctionName() or "") .. " with arguments: " .. util.dump(rq:getAll())) diff --git a/src/network/netconfig.lua b/src/network/netconfig.lua index 5073eed..f7fb184 100644 --- a/src/network/netconfig.lua +++ b/src/network/netconfig.lua @@ -267,6 +267,7 @@ end -- @tparam boolean recreate If true, a new UCI configuration based on scan data will always be created, otherwise an attempt will be made to use an existing configuration. -- @return True on success or nil+msg on error. function M.associateSsid(ssid, passphrase, recreate) + log:info("netconfig:associateSsid: "..(ssid or "")..", "..(passphrase or "")..", "..(recreate or "")) -- see if previously configured network for given ssid exists local cfg = nil for _, net in ipairs(wifi.getConfigs()) do @@ -275,7 +276,7 @@ function M.associateSsid(ssid, passphrase, recreate) break end end - + -- if not, or if newly created configuration is requested, create a new configuration if cfg == nil or recreate ~= nil then local scanResult = wifi.getScanInfo(ssid) @@ -291,10 +292,10 @@ function M.associateSsid(ssid, passphrase, recreate) wifi.activateConfig(ssid) --M.switchConfiguration{ wifiiface="add", apnet="rm", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wwwcaptive="rm", wireless="reload" } --M.switchConfiguration{ wifiiface="add", apnet="rm", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" } - M.switchConfiguration{ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" } + M.switchConfiguration{ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" } -- check if we are actually associated - local status = wifi.getDeviceState() + local status = wifi.getDeviceState() if not status.ssid or status.ssid ~= ssid then return nil,"could not associate with network (incorrect passphrase?)" end diff --git a/src/network/wlanconfig.lua b/src/network/wlanconfig.lua index eab892a..b089a86 100644 --- a/src/network/wlanconfig.lua +++ b/src/network/wlanconfig.lua @@ -175,35 +175,36 @@ end --- Activate wireless section for given SSID and disable all others -- @param ssid SSID of config to enable, or nil to disable all network configs function M.activateConfig(ssid) + --log:info("wlanconfig.activateConfig: "..ssid); - --local utils = require('util.utils') - --local log = require('util.logger') - --log:info("wlanconfig:activateConfig: "..utils.dump(ssid)) - - -- make sure only one is enabled - uci:foreach('wireless', 'wifi-iface', function(s) + -- make sure only one is enabled + uci:foreach('wireless', 'wifi-iface', function(s) local disabled = s.ssid ~= ssid and '1' or '0' - --log:info(" "..utils.dump(s.ssid).." disable: "..utils.dump(disabled)) + --log:info(" "..utils.dump(s.ssid).." disable: "..utils.dump(disabled)) uci:set('wireless', s['.name'], 'disabled', disabled) end) uci:commit('wireless') - -- make sure the wifi-device radio0 is on top - uci:reorder('wireless', 'radio0', 0) + -- make sure the wifi-device radio0 is on top + uci:reorder('wireless', 'radio0', 0) uci:commit('wireless') - -- put it on top of the wireless configuration so it's the first option when the devices starts - uci:foreach('wireless', 'wifi-iface', function(s) + -- put it on top of the wireless configuration so it's the first option when the devices starts + uci:foreach('wireless', 'wifi-iface', function(s) if s.ssid == ssid then - uci:reorder('wireless', s['.name'], 1) + uci:reorder('wireless', s['.name'], 1) return false end end) + --[[log:info(" result:"); + uci:foreach('wireless', 'wifi-iface', function(s) + local disabled = s.ssid ~= ssid and '1' or '0' + log:info(" "..utils.dump(s.ssid).." disable: "..utils.dump(disabled)) + end)]]-- uci:commit('wireless') - end --- Create a new UCI network from the given iwinfo data diff --git a/src/rest/api/api_network.lua b/src/rest/api/api_network.lua index f6ffda9..4c43935 100644 --- a/src/rest/api/api_network.lua +++ b/src/rest/api/api_network.lua @@ -78,7 +78,12 @@ function M.status(request, response) local withRaw = utils.toboolean(request:get("with_raw")) local ds = wifi.getDeviceState() - response:setSuccess() + if ds.ssid == nil then + response:setFail("Not connected") + else + response:setSuccess() + end + response:addData("ssid", ds.ssid or "") response:addData("bssid", ds.bssid or "") response:addData("channel", ds.channel or "") diff --git a/src/script/wifibox_init b/src/script/wifibox_init index d1b7b78..d766af6 100755 --- a/src/script/wifibox_init +++ b/src/script/wifibox_init @@ -6,6 +6,8 @@ START=22 LOGGER="logger -s -t autowifi -p 6" boot() { + sleep 1 + $LOGGER "Invoking Doodle3D WiFi box network auto-initialization..." /usr/share/lua/wifibox/script/d3dapi autowifi