mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 19:13:49 +01:00
Report failure if wlan associate fails; Fix setting/unsetting boolean config key through API.
This commit is contained in:
parent
6ee8b0193e
commit
1608875891
@ -11,7 +11,7 @@ function M._global_GET(request, response)
|
||||
for k,v in pairs(request:getAll()) do
|
||||
local r,m = settings.get(k)
|
||||
|
||||
if r then response:addData(k, r)
|
||||
if r ~= nil then response:addData(k, r)
|
||||
else response:addData(k, "could not read key ('" .. m .. "')")
|
||||
end
|
||||
end
|
||||
|
@ -124,11 +124,16 @@ function M.associate_POST(request, response)
|
||||
wifi.activateConfig(argSsid)
|
||||
--netconf.switchConfiguration{ wifiiface="add", apnet="rm", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wwwcaptive="rm", wireless="reload" }
|
||||
netconf.switchConfiguration{ wifiiface="add", apnet="rm", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" }
|
||||
response:setSuccess("wlan associated")
|
||||
|
||||
local status = wifi.getDeviceState()
|
||||
response:addData("ssid", argSsid)
|
||||
if status.ssid and status.ssid == argSsid then
|
||||
response:setSuccess("wlan associated")
|
||||
else
|
||||
response:setFail("could not associate with network (incorrect pass phrase?)")
|
||||
end
|
||||
end
|
||||
|
||||
--UNTESTED
|
||||
function M.disassociate_POST(request, response)
|
||||
wifi.activateConfig()
|
||||
local rv = wifi.restart()
|
||||
@ -145,7 +150,6 @@ function M.openap_POST(request, response)
|
||||
response:addData("ssid", ssid)
|
||||
end
|
||||
|
||||
--UNTESTED
|
||||
--requires ssid(string)
|
||||
function M.remove_POST(request, response)
|
||||
local argSsid = request:get("ssid")
|
||||
|
@ -37,7 +37,7 @@ local function kvTableFromArray(argArray)
|
||||
for _, v in ipairs(argArray) do
|
||||
local split = v:find("=")
|
||||
if split ~= nil then
|
||||
args[v:sub(1, split - 1)] = v:sub(split + 1)
|
||||
args[v:sub(1, split - 1)] = urlcode.unescape(v:sub(split + 1))
|
||||
else
|
||||
args[v] = true
|
||||
end
|
||||
@ -101,7 +101,10 @@ local function resolveApiFunction(modname, funcname, requestMethod)
|
||||
local mod, msg = resolveApiModule(modname)
|
||||
|
||||
if mod == nil then
|
||||
return nil, msg
|
||||
-- error is indicated by leaving out 'func' key and adding 'notfound'=true
|
||||
resultData.notfound = true
|
||||
resultData.msg = msg
|
||||
return resultData
|
||||
end
|
||||
|
||||
if (funcname == nil or funcname == '') then funcname = GLOBAL_API_FUNCTION_NAME end --treat empty function name as nil
|
||||
@ -175,7 +178,7 @@ function M.new(postData, debugEnabled)
|
||||
if debugEnabled and self.requestMethod == 'CMDLINE' then
|
||||
self.pathArgs = arrayFromPath(self.cmdLineArgs['p'])
|
||||
|
||||
if self.cmdLineArgs['r'] == 'GET' then
|
||||
if self.cmdLineArgs['r'] == 'GET' or self.cmdLineArgs['r'] == nil then
|
||||
self.requestMethod = 'GET'
|
||||
self.getArgs = self.cmdLineArgs
|
||||
self.getArgs.p, self.getArgs.r = nil, nil
|
||||
@ -197,6 +200,7 @@ function M.new(postData, debugEnabled)
|
||||
|
||||
-- Perform module/function resolution
|
||||
local rData = resolveApiFunction(self:getRequestedApiModule(), self:getRequestedApiFunction(), self.requestMethod)
|
||||
local modFuncInfo = self:getRequestedApiModule() or "<>" .. "/" .. self:getRequestedApiFunction() or "<>"
|
||||
|
||||
if rData.func ~= nil then --function (possibly the global one) could be resolved
|
||||
self.resolvedApiFunction = rData.func
|
||||
@ -212,9 +216,9 @@ function M.new(postData, debugEnabled)
|
||||
end
|
||||
end
|
||||
elseif rData.notfound == true then
|
||||
self.resolutionError = "module/function '" .. self:getRequestedApiModule() .. "/" .. self:getRequestedApiFunction() .. "' does not exist"
|
||||
self.resolutionError = "module/function '" .. modFuncInfo .. "' does not exist"
|
||||
else
|
||||
self.resolutionError = "module/function '" .. self:getRequestedApiModule() .. "/" .. self:getRequestedApiFunction() .. "' can only be accessed with the " .. rData.accessType .. " method"
|
||||
self.resolutionError = "module/function '" .. modFuncInfo .. "' can only be accessed with the " .. rData.accessType .. " method"
|
||||
end
|
||||
|
||||
return self
|
||||
|
@ -188,12 +188,15 @@ function M.set(key, value)
|
||||
|
||||
local current = uci:get(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key)
|
||||
|
||||
-- TODO: test if this fixes setting bools (and does not break settings the other types)
|
||||
-- if base.type == 'bool' then
|
||||
-- value = utils.toboolean(value)
|
||||
-- elseif base.type == 'int' or base.type == 'float' then
|
||||
-- value = tonumber(value)
|
||||
-- end
|
||||
if base.type == 'bool' then
|
||||
if value ~= "" then
|
||||
value = utils.toboolean(value)
|
||||
else
|
||||
value = nil
|
||||
end
|
||||
elseif base.type == 'int' or base.type == 'float' then
|
||||
value = tonumber(value)
|
||||
end
|
||||
|
||||
if fromUciValue(current, base.type) == value then return true end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user