Fixed boot wifi connection issues by adding sleep

This commit is contained in:
peteruithoven 2013-10-04 16:29:53 +02:00
parent d083ee70dd
commit 37783f3f06
5 changed files with 36 additions and 26 deletions

View File

@ -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 "<unknown>")
-- .. "/" .. (rq:getRealApiFunctionName() or "<unknown>") .. " with arguments: " .. util.dump(rq:getAll()))

View File

@ -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 "<nil>")..", "..(passphrase or "<nil>")..", "..(recreate or "<nil>"))
-- 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

View File

@ -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

View File

@ -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 "")

View File

@ -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