mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 02:53:49 +01:00
Fix problem where 'wlan0' device disappears (code now falls back to 'radio0'); fix symlink path for captive portal www; minor fixes.
This commit is contained in:
parent
b861f43e11
commit
e2127797de
25
src/main.lua
25
src/main.lua
@ -1,19 +1,21 @@
|
||||
--[[
|
||||
TODO:
|
||||
- document REST API (mention rq IDs and endpoint information, list endpoints+args+CRUD type, unknown values are empty fields)
|
||||
(describe fail/error difference: fail is valid rq..could not comply, while error is invalid rq _or_ system error)
|
||||
- use a slightly more descriptive success/error definition (e.g. errortype=system/missing-arg/generic)
|
||||
- how to handle requests which need a restart of uhttpd? (e.g. network/openap)
|
||||
- a plain GET request (no ajax/script) runs the risk of timing out on lengthy operations: implement polling in API to get progress updates?
|
||||
(this would require those operations to run in a separate daemon process which can be monitored by the CGI handler)
|
||||
- protect dump function against reference loops (see: http://lua-users.org/wiki/TableSerialization, json also handles this well)
|
||||
- (this is an old todo item from network:available(), might still be relevant at some point)
|
||||
extend reconf interface to support function arguments (as tables) so wifihelper functionality can be integrated
|
||||
extend netconf interface to support function arguments (as tables) so wifihelper functionality can be integrated
|
||||
but how? idea: pass x_args={arg1="a",arg2="2342"} for component 'x'
|
||||
or: allow alternative for x="y" --> x={action="y", arg1="a", arg2="2342"}
|
||||
in any case, arguments should be put in a new table to pass to the function (since order is undefined it must be an assoc array)
|
||||
|
||||
NOTES:
|
||||
- using iwinfo with interface name 'radio0' yields very little 'info' output while wlan0 works fine
|
||||
- using iwinfo with interface name 'radio0' yields very little 'info' output while wlan0 works fine.
|
||||
However, sometimes wlan0 disappears (happened after trying to associate with non-existing network)...why?
|
||||
- The endpoint function info in response objects is incorrect when the global function is called with a blank argument,
|
||||
to cleanly solve this, module/function resolution should be moved from main() to the request object
|
||||
]]--
|
||||
@ -22,7 +24,7 @@ local l = require("logger")
|
||||
local RequestClass = require("rest.request")
|
||||
local ResponseClass = require("rest.response")
|
||||
local wifi = require("network.wlanconfig")
|
||||
local reconf = require("network.netconfig")
|
||||
local netconf = require("network.netconfig")
|
||||
|
||||
|
||||
--NOTE: pcall protects from invocation exceptions, which is what we need except
|
||||
@ -50,7 +52,14 @@ local function init()
|
||||
postData = io.read(n)
|
||||
end
|
||||
|
||||
return wifi.init() and reconf.init(wifi, true)
|
||||
local s, msg
|
||||
s, msg = wifi.init()
|
||||
if not s then return s, msg end
|
||||
|
||||
s, msg = netconf.init(wifi, true)
|
||||
if not s then return s, msg end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--usually returns function+nil, function+number in case of number in place of function name; or
|
||||
@ -135,12 +144,12 @@ end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if init() == false then
|
||||
local s, msg = init()
|
||||
if s == false then
|
||||
local resp = ResponseClass.new()
|
||||
resp:setError("initialization failed")
|
||||
resp:setError("initialization failed (" .. msg .. ")")
|
||||
print(resp:serializeAsJson()) --FIXME: this message does not seem to be sent
|
||||
l:error("initialization failed") --NOTE: this assumes the logger has been inited properly, despite init() having failed
|
||||
l:error("initialization failed (" .. msg .. ")") --NOTE: this assumes the logger has been inited properly, despite init() having failed
|
||||
os.exit(1)
|
||||
else
|
||||
main()
|
||||
|
@ -7,7 +7,7 @@ local reconf = {}
|
||||
local wifi
|
||||
local reloadSilent
|
||||
|
||||
M.WWW_CAPTIVE_PATH = "/usr/share/lua/wifibox/ext/www"
|
||||
M.WWW_CAPTIVE_PATH = "/usr/share/lua/wifibox/www"
|
||||
M.WWW_CAPTIVE_INDICATOR = "/www/.wifibox-inplace"
|
||||
M.WWW_RENAME_NAME = "/www-regular"
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
local reconf = require("network.netconfig")
|
||||
local util = require("util.utils")
|
||||
local l = require("logger")
|
||||
local uci = require("uci").cursor()
|
||||
@ -6,7 +5,9 @@ local iwinfo = require("iwinfo")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.DFL_DEVICE = "wlan0" -- was radio0
|
||||
--NOTE: fallback device 'radio0' is required because sometimes the wlan0 device disappears
|
||||
M.DFL_DEVICE = "wlan0"
|
||||
M.DFL_DEVICE_FALLBACK = "radio0"
|
||||
M.AP_SSID = "d3d-ap"
|
||||
M.AP_ADDRESS = "192.168.10.1"
|
||||
M.AP_NETMASK = "255.255.255.0"
|
||||
@ -50,7 +51,14 @@ function M.init(device)
|
||||
dev = device or M.DFL_DEVICE
|
||||
dev_api = iwinfo.type(dev)
|
||||
if not dev_api then
|
||||
return false, "No such wireless device: '"..dev.."'"
|
||||
--TODO: warn about missing dev here?
|
||||
local devInitial = dev
|
||||
dev = M.DFL_DEVICE_FALLBACK
|
||||
dev_api = iwinfo.type(dev)
|
||||
|
||||
if not dev_api then
|
||||
return false, "No such wireless device: '" .. devInitial .. "' (and fallback '" .. dev .. "' does not exist either)"
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
|
@ -44,7 +44,7 @@ function M.available(d)
|
||||
r:addData("count", #netInfoList)
|
||||
r:addData("networks", netInfoList)
|
||||
else
|
||||
r:setError("No scan results or scanning not possible")
|
||||
r:setFail("No scan results or scanning not possible")
|
||||
end
|
||||
|
||||
return r
|
||||
@ -121,7 +121,7 @@ function M.assoc(d)
|
||||
wifi.createConfigFromScanInfo(scanResult, argPhrase)
|
||||
else
|
||||
--check for error
|
||||
r:setError("no wireless network with requested SSID is available")
|
||||
r:setFail("no wireless network with requested SSID is available")
|
||||
r:addData("ssid", argSsid)
|
||||
end
|
||||
end
|
||||
@ -175,7 +175,7 @@ function M.rm(d)
|
||||
r:setSuccess("removed wireless network with requested SSID")
|
||||
r:addData("ssid", argSsid)
|
||||
else
|
||||
r:setError("no wireless network with requested SSID") --this used to be a warning instead of an error...
|
||||
r:setFail("no wireless network with requested SSID") --this used to be a warning instead of an error...
|
||||
r:addData("ssid", argSsid)
|
||||
end
|
||||
|
||||
|
@ -21,6 +21,12 @@ function M.success(d)
|
||||
return r
|
||||
end
|
||||
|
||||
function M.fail(d)
|
||||
local r = ResponseClass.new(d)
|
||||
r:setFail()
|
||||
return r
|
||||
end
|
||||
|
||||
function M.error(d)
|
||||
local r = ResponseClass.new(d)
|
||||
r:setError("this error has been generated on purpose")
|
||||
|
@ -31,15 +31,21 @@ function M.new(requestObject)
|
||||
return self
|
||||
end
|
||||
|
||||
function M:setStatus(s)
|
||||
self.body.status = s
|
||||
end
|
||||
--use set{Success|Fail|Error}()
|
||||
--function M:setStatus(s)
|
||||
-- self.body.status = s
|
||||
--end
|
||||
|
||||
function M:setSuccess(msg)
|
||||
self.body.status = "success"
|
||||
if msg ~= "" then self.body.msg = msg end
|
||||
end
|
||||
|
||||
function M:setFail(msg)
|
||||
self.body.status = "fail"
|
||||
if msg ~= "" then self.body.msg = msg end
|
||||
end
|
||||
|
||||
function M:setError(msg)
|
||||
self.body.status = "error"
|
||||
if msg ~= "" then self.body.msg = msg end
|
||||
|
Loading…
Reference in New Issue
Block a user