mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
Reorder and rename log levels to match those in print server.
Fix typo in regex in getLocalIp function. Conflicts: src/script/wifibox.uci.config
This commit is contained in:
parent
3a3abb9c55
commit
2459cda0ac
10
src/main.lua
10
src/main.lua
@ -125,7 +125,7 @@ end
|
|||||||
-- @treturn bool True on success, false on error.
|
-- @treturn bool True on success, false on error.
|
||||||
local function setupLogger()
|
local function setupLogger()
|
||||||
local logStream = io.stderr -- use stderr as hard-coded default target
|
local logStream = io.stderr -- use stderr as hard-coded default target
|
||||||
local logLevel = log.LEVEL.debug -- use debug logging as hard-coded default level
|
local logLevel = log.LEVEL.verbose -- use verbose logging as hard-coded default level
|
||||||
|
|
||||||
local logTargetSetting = settings.getSystemKey('logfile')
|
local logTargetSetting = settings.getSystemKey('logfile')
|
||||||
local logLevelSetting = settings.get('system.log.level')
|
local logLevelSetting = settings.get('system.log.level')
|
||||||
@ -178,7 +178,7 @@ local function setupLogger()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if logLevelError then
|
if logLevelError then
|
||||||
log:error("uci config specifies invalid log level '" .. logLevelSetting .. "', using debug level as fallback")
|
log:error("uci config specifies invalid log level '" .. logLevelSetting .. "', using verbose level as fallback")
|
||||||
rv = false
|
rv = false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -222,10 +222,10 @@ local function main(environment)
|
|||||||
local rq = RequestClass.new(environment, postData, confDefaults.DEBUG_API)
|
local rq = RequestClass.new(environment, postData, confDefaults.DEBUG_API)
|
||||||
|
|
||||||
if rq:getRequestMethod() == 'CMDLINE' and rq:get('autowifi') ~= nil then
|
if rq:getRequestMethod() == 'CMDLINE' and rq:get('autowifi') ~= nil then
|
||||||
|
|
||||||
local version = updater.formatVersion(updater.getCurrentVersion());
|
local version = updater.formatVersion(updater.getCurrentVersion());
|
||||||
log:info("Doodle3D version: "..util.dump(version))
|
log:info("Doodle3D version: "..util.dump(version))
|
||||||
|
|
||||||
log:info("running in autowifi mode")
|
log:info("running in autowifi mode")
|
||||||
local rv,msg = setupAutoWifiMode()
|
local rv,msg = setupAutoWifiMode()
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ local function main(environment)
|
|||||||
.. "/" .. (rq:getRealApiFunctionName() or "<unknown>"))
|
.. "/" .. (rq:getRealApiFunctionName() or "<unknown>"))
|
||||||
if rq:getRequestMethod() ~= 'CMDLINE' then
|
if rq:getRequestMethod() ~= 'CMDLINE' then
|
||||||
log:info("remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort())
|
log:info("remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort())
|
||||||
--log:debug("user agent: " .. rq:getUserAgent())
|
--log:verbose("user agent: " .. rq:getUserAgent())
|
||||||
end
|
end
|
||||||
|
|
||||||
local response, err = rq:handle()
|
local response, err = rq:handle()
|
||||||
|
@ -25,9 +25,9 @@ M.WWW_RENAME_NAME = '/www-regular'
|
|||||||
M.CONNECTING_FAILED = -1
|
M.CONNECTING_FAILED = -1
|
||||||
M.NOT_CONNECTED = 0
|
M.NOT_CONNECTED = 0
|
||||||
M.CONNECTING = 1
|
M.CONNECTING = 1
|
||||||
M.CONNECTED = 2
|
M.CONNECTED = 2
|
||||||
M.CREATING = 3
|
M.CREATING = 3
|
||||||
M.CREATED = 4
|
M.CREATED = 4
|
||||||
|
|
||||||
local function reloadBit(dlist, itemname)
|
local function reloadBit(dlist, itemname)
|
||||||
if dlist[itemname] == nil then dlist[itemname] = '' end
|
if dlist[itemname] == nil then dlist[itemname] = '' end
|
||||||
@ -62,10 +62,10 @@ function M.switchConfiguration(components)
|
|||||||
for k,v in pairs(components) do
|
for k,v in pairs(components) do
|
||||||
local fname = k .. '_' .. v
|
local fname = k .. '_' .. v
|
||||||
if type(reconf[fname]) == 'function' then
|
if type(reconf[fname]) == 'function' then
|
||||||
log:debug("reconfiguring component '" .. k .. "' (" .. v .. ")")
|
log:verbose("reconfiguring component '" .. k .. "' (" .. v .. ")")
|
||||||
reconf[fname](dirtyList)
|
reconf[fname](dirtyList)
|
||||||
else
|
else
|
||||||
log:warn("unknown component or action '" .. fname .. "' skipped")
|
log:warning("unknown component or action '" .. fname .. "' skipped")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -84,15 +84,15 @@ function M.commitComponent(c)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.reloadComponent(c, silent)
|
function M.reloadComponent(c, silent)
|
||||||
log:info("reloading component '" .. c .. "'")
|
log:info("reloading component '" .. c .. "'")
|
||||||
local command = 'reload'
|
local command = 'reload'
|
||||||
local cmd = '/etc/init.d/' .. c .. ' '..command
|
local cmd = '/etc/init.d/' .. c .. ' '..command
|
||||||
if silent ~= nil and silent then
|
if silent ~= nil and silent then
|
||||||
cmd = cmd .. ' &> /dev/null'
|
cmd = cmd .. ' &> /dev/null'
|
||||||
os.execute(cmd)
|
os.execute(cmd)
|
||||||
else
|
else
|
||||||
rv = utils.captureCommandOutput(cmd)
|
rv = utils.captureCommandOutput(cmd)
|
||||||
log:debug(" result reloading component '" .. c .. "' (cmd: '"..cmd.."'): \n"..utils.dump(rv))
|
log:verbose(" result reloading component '" .. c .. "' (cmd: '"..cmd.."'): \n"..utils.dump(rv))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -213,7 +213,7 @@ function reconf.dnsredir_add(dirtyList)
|
|||||||
local redirText = '/#/' .. settings.get('network.ap.address')
|
local redirText = '/#/' .. settings.get('network.ap.address')
|
||||||
local sname = utils.getUciSectionName('dhcp', 'dnsmasq')
|
local sname = utils.getUciSectionName('dhcp', 'dnsmasq')
|
||||||
if sname == nil then return log:error("dhcp config does not contain a dnsmasq section") end
|
if sname == nil then return log:error("dhcp config does not contain a dnsmasq section") end
|
||||||
if uci:get('dhcp', sname, 'address') ~= nil then return log:debug("DNS address redirection already in place, not re-adding", false) end
|
if uci:get('dhcp', sname, 'address') ~= nil then return log:verbose("DNS address redirection already in place, not re-adding", false) end
|
||||||
|
|
||||||
uci:set('dhcp', sname, 'address', {redirText})
|
uci:set('dhcp', sname, 'address', {redirText})
|
||||||
commitBit(dirtyList, 'dhcp'); reloadBit(dirtyList, 'dnsmasq')
|
commitBit(dirtyList, 'dhcp'); reloadBit(dirtyList, 'dnsmasq')
|
||||||
@ -230,7 +230,7 @@ end
|
|||||||
--TODO: handle os.rename() return values (nil+msg on error)
|
--TODO: handle os.rename() return values (nil+msg on error)
|
||||||
function reconf.wwwcaptive_add(dirtyList)
|
function reconf.wwwcaptive_add(dirtyList)
|
||||||
if utils.exists(M.WWW_CAPTIVE_INDICATOR) then
|
if utils.exists(M.WWW_CAPTIVE_INDICATOR) then
|
||||||
return log:debug("WWW captive directory already in place, not redoing", false)
|
return log:verbose("WWW captive directory already in place, not redoing", false)
|
||||||
end
|
end
|
||||||
local rv,reason = os.rename('/www', M.WWW_RENAME_NAME)
|
local rv,reason = os.rename('/www', M.WWW_RENAME_NAME)
|
||||||
if rv == true then
|
if rv == true then
|
||||||
@ -241,7 +241,7 @@ function reconf.wwwcaptive_add(dirtyList)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function reconf.wwwcaptive_rm(dirtyList)
|
function reconf.wwwcaptive_rm(dirtyList)
|
||||||
if not utils.exists(M.WWW_CAPTIVE_INDICATOR) then return log:debug("WWW captive directory not in place, not undoing", false) end
|
if not utils.exists(M.WWW_CAPTIVE_INDICATOR) then return log:verbose("WWW captive directory not in place, not undoing", false) end
|
||||||
os.remove('/www')
|
os.remove('/www')
|
||||||
if os.rename(M.WWW_RENAME_NAME, '/www') ~= true then
|
if os.rename(M.WWW_RENAME_NAME, '/www') ~= true then
|
||||||
return log:error("Could not rename " .. M.WWW_RENAME_NAME .. " to /www")
|
return log:error("Could not rename " .. M.WWW_RENAME_NAME .. " to /www")
|
||||||
@ -275,16 +275,16 @@ end
|
|||||||
-- @return True on success or nil+msg on error.
|
-- @return True on success or nil+msg on error.
|
||||||
function M.setupAccessPoint(ssid)
|
function M.setupAccessPoint(ssid)
|
||||||
M.setStatus(M.CREATING,"Creating access point '"..ssid.."'...");
|
M.setStatus(M.CREATING,"Creating access point '"..ssid.."'...");
|
||||||
|
|
||||||
-- add access point configuration
|
-- add access point configuration
|
||||||
M.switchConfiguration({apnet="add_noreload"})
|
M.switchConfiguration({apnet="add_noreload"})
|
||||||
wifi.activateConfig(ssid)
|
wifi.activateConfig(ssid)
|
||||||
-- NOTE: dnsmasq must be reloaded after network or it will be unable to serve IP addresses
|
-- NOTE: dnsmasq must be reloaded after network or it will be unable to serve IP addresses
|
||||||
M.switchConfiguration({ wifiiface="add", network="reload", staticaddr="add", dhcppool="add_noreload", wwwredir="add", dnsredir="add" })
|
M.switchConfiguration({ wifiiface="add", network="reload", staticaddr="add", dhcppool="add_noreload", wwwredir="add", dnsredir="add" })
|
||||||
M.switchConfiguration({dhcp="reload"})
|
M.switchConfiguration({dhcp="reload"})
|
||||||
|
|
||||||
M.setStatus(M.CREATED,"Access point created");
|
M.setStatus(M.CREATED,"Access point created");
|
||||||
|
|
||||||
local ds = wifi.getDeviceState()
|
local ds = wifi.getDeviceState()
|
||||||
--log:info(" network/status: ")
|
--log:info(" network/status: ")
|
||||||
log:info(" ssid: ".. utils.dump(ds.ssid))
|
log:info(" ssid: ".. utils.dump(ds.ssid))
|
||||||
@ -298,10 +298,10 @@ function M.setupAccessPoint(ssid)
|
|||||||
log:info(" signal: ".. utils.dump(ds.signal))
|
log:info(" signal: ".. utils.dump(ds.signal))
|
||||||
log:info(" noise: ".. utils.dump(ds.noise))
|
log:info(" noise: ".. utils.dump(ds.noise))
|
||||||
log:info(" raw: ".. utils.dump(ds))
|
log:info(" raw: ".. utils.dump(ds))
|
||||||
|
|
||||||
local localip = wifi.getLocalIP()
|
local localip = wifi.getLocalIP()
|
||||||
log:info(" localip: "..utils.dump(localip))]]--
|
log:info(" localip: "..utils.dump(localip))]]--
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -311,14 +311,14 @@ end
|
|||||||
-- @tparam string ssid The SSID to use for the access point.
|
-- @tparam string ssid The SSID to use for the access point.
|
||||||
-- @return True on success or nil+msg on error.
|
-- @return True on success or nil+msg on error.
|
||||||
function M.enableAccessPoint(ssid)
|
function M.enableAccessPoint(ssid)
|
||||||
log:debug("enableAccessPoint ssid: ".. utils.dump(ssid))
|
log:verbose("enableAccessPoint ssid: ".. utils.dump(ssid))
|
||||||
|
|
||||||
M.switchConfiguration{apnet="add_noreload"}
|
M.switchConfiguration{apnet="add_noreload"}
|
||||||
wifi.activateConfig(ssid)
|
wifi.activateConfig(ssid)
|
||||||
|
|
||||||
local ds = wifi.getDeviceState()
|
local ds = wifi.getDeviceState()
|
||||||
log:debug(" ssid: ".. utils.dump(ds.ssid))
|
log:verbose(" ssid: ".. utils.dump(ds.ssid))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -332,7 +332,7 @@ end
|
|||||||
function M.associateSsid(ssid, passphrase, recreate)
|
function M.associateSsid(ssid, passphrase, recreate)
|
||||||
log:info("netconfig:associateSsid: "..(ssid or "<nil>")..", "..(recreate or "<nil>"))
|
log:info("netconfig:associateSsid: "..(ssid or "<nil>")..", "..(recreate or "<nil>"))
|
||||||
M.setStatus(M.CONNECTING,"Connecting...");
|
M.setStatus(M.CONNECTING,"Connecting...");
|
||||||
|
|
||||||
-- see if previously configured network for given ssid exists
|
-- see if previously configured network for given ssid exists
|
||||||
local cfg = nil
|
local cfg = nil
|
||||||
for _, net in ipairs(wifi.getConfigs()) do
|
for _, net in ipairs(wifi.getConfigs()) do
|
||||||
@ -341,7 +341,7 @@ function M.associateSsid(ssid, passphrase, recreate)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if not, or if newly created configuration is requested, create a new configuration
|
-- if not, or if newly created configuration is requested, create a new configuration
|
||||||
if cfg == nil or recreate ~= nil then
|
if cfg == nil or recreate ~= nil then
|
||||||
local scanResult, msg = wifi.getScanInfo(ssid)
|
local scanResult, msg = wifi.getScanInfo(ssid)
|
||||||
@ -365,16 +365,16 @@ function M.associateSsid(ssid, passphrase, recreate)
|
|||||||
--M.switchConfiguration{ wifiiface="add", apnet="rm", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="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" }
|
||||||
M.switchConfiguration({ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm" })
|
M.switchConfiguration({ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm" })
|
||||||
|
|
||||||
-- we check if we get a ssid and ip in max 5 seconds
|
-- we check if we get a ssid and ip in max 5 seconds
|
||||||
-- if not there is probably a issue
|
-- if not there is probably a issue
|
||||||
local attemptInterval = 1
|
local attemptInterval = 1
|
||||||
local maxAttempts = 5
|
local maxAttempts = 5
|
||||||
local attempt = 0
|
local attempt = 0
|
||||||
local nextAttemptTime = os.time()
|
local nextAttemptTime = os.time()
|
||||||
while true do
|
while true do
|
||||||
if os.time() > nextAttemptTime then
|
if os.time() > nextAttemptTime then
|
||||||
log:debug("associated check "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
|
log:verbose("associated check "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
|
||||||
if wifi.getLocalIP() ~= nil and wifi.getDeviceState().ssid == ssid then
|
if wifi.getLocalIP() ~= nil and wifi.getDeviceState().ssid == ssid then
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
@ -390,18 +390,18 @@ function M.associateSsid(ssid, passphrase, recreate)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- signin to connect.doodle3d.com
|
-- signin to connect.doodle3d.com
|
||||||
local success, output = signin.signin()
|
local success, output = signin.signin()
|
||||||
if success then
|
if success then
|
||||||
log:info("Signed in")
|
log:info("Signed in")
|
||||||
else
|
else
|
||||||
log:info("Signing in failed")
|
log:info("Signing in failed")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- report we are connected after signin attempt
|
-- report we are connected after signin attempt
|
||||||
M.setStatus(M.CONNECTED,"Connected");
|
M.setStatus(M.CONNECTED,"Connected");
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
--- Disassociate wlan device as client from all SSID's.
|
--- Disassociate wlan device as client from all SSID's.
|
||||||
@ -411,7 +411,7 @@ end
|
|||||||
function M.disassociate()
|
function M.disassociate()
|
||||||
|
|
||||||
M.setStatus(M.NOT_CONNECTED,"Not connected");
|
M.setStatus(M.NOT_CONNECTED,"Not connected");
|
||||||
|
|
||||||
wifi.activateConfig()
|
wifi.activateConfig()
|
||||||
return wifi.restart()
|
return wifi.restart()
|
||||||
end
|
end
|
||||||
|
@ -28,54 +28,54 @@ local SIGNING_IN_STATUS = 2
|
|||||||
--
|
--
|
||||||
function M.signin()
|
function M.signin()
|
||||||
|
|
||||||
--log:debug("signin:signin");
|
--log:verbose("signin:signin");
|
||||||
|
|
||||||
local code, msg = M.getStatus()
|
local code, msg = M.getStatus()
|
||||||
--log:debug(" status: "..utils.dump(code).." "..utils.dump(msg));
|
--log:verbose(" status: "..utils.dump(code).." "..utils.dump(msg));
|
||||||
|
|
||||||
-- if we are already signin in, skip
|
-- if we are already signin in, skip
|
||||||
if(code == SIGNING_IN_STATUS) then
|
if(code == SIGNING_IN_STATUS) then
|
||||||
log:debug(" skipping signin")
|
log:verbose(" skipping signin")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
M.setStatus(SIGNING_IN_STATUS,"signing in")
|
M.setStatus(SIGNING_IN_STATUS,"signing in")
|
||||||
|
|
||||||
local baseurl = "http://connect.doodle3d.com/api/signin.php"
|
local baseurl = "http://connect.doodle3d.com/api/signin.php"
|
||||||
|
|
||||||
local attemptInterval = 1
|
local attemptInterval = 1
|
||||||
local maxAttempts = 20
|
local maxAttempts = 20
|
||||||
local attempt = 0
|
local attempt = 0
|
||||||
|
|
||||||
local nextAttemptTime = os.time()
|
local nextAttemptTime = os.time()
|
||||||
|
|
||||||
local localip = ""
|
local localip = ""
|
||||||
local signinResponse = ""
|
local signinResponse = ""
|
||||||
while true do
|
while true do
|
||||||
if os.time() > nextAttemptTime then
|
if os.time() > nextAttemptTime then
|
||||||
log:debug("signin attempt "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
|
log:verbose("signin attempt "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
|
||||||
local signedin = false
|
local signedin = false
|
||||||
local localip = wifi.getLocalIP();
|
local localip = wifi.getLocalIP();
|
||||||
--log:debug(" localip: "..utils.dump(localip))
|
--log:verbose(" localip: "..utils.dump(localip))
|
||||||
if localip ~= nil then
|
if localip ~= nil then
|
||||||
|
|
||||||
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
||||||
wifiboxid = urlcode.escape(wifiboxid)
|
wifiboxid = urlcode.escape(wifiboxid)
|
||||||
|
|
||||||
local cmd = "wget -q -T 2 -t 1 -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
local cmd = "wget -q -T 2 -t 1 -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
||||||
signinResponse = utils.captureCommandOutput(cmd);
|
signinResponse = utils.captureCommandOutput(cmd);
|
||||||
log:debug(" signin response: \n"..utils.dump(signinResponse))
|
log:verbose(" signin response: \n"..utils.dump(signinResponse))
|
||||||
local success = signinResponse:match('"status":"success"')
|
local success = signinResponse:match('"status":"success"')
|
||||||
log:debug(" success: "..utils.dump(success))
|
log:verbose(" success: "..utils.dump(success))
|
||||||
if success ~= nil then
|
if success ~= nil then
|
||||||
signedin = true
|
signedin = true
|
||||||
else
|
else
|
||||||
log:warn("signin failed request failed (response: "..utils.dump(signinResponse)..")")
|
log:warning("signin failed request failed (response: "..utils.dump(signinResponse)..")")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
log:warn("signin failed no local ip found (attempt: "..utils.dump(attempt).."/"..utils.dump(maxAttempts)..")")
|
log:warning("signin failed no local ip found (attempt: "..utils.dump(attempt).."/"..utils.dump(maxAttempts)..")")
|
||||||
end
|
end
|
||||||
|
|
||||||
if signedin then
|
if signedin then
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
@ -90,7 +90,7 @@ function M.signin()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.setStatus(IDLE_STATUS,"idle")
|
M.setStatus(IDLE_STATUS,"idle")
|
||||||
return string.len(signinResponse) > 0, signinResponse
|
return string.len(signinResponse) > 0, signinResponse
|
||||||
end
|
end
|
||||||
|
@ -126,9 +126,10 @@ end
|
|||||||
--returns the wireless local ip address
|
--returns the wireless local ip address
|
||||||
function M.getLocalIP()
|
function M.getLocalIP()
|
||||||
local ifconfig, rv = utils.captureCommandOutput("ifconfig wlan0");
|
local ifconfig, rv = utils.captureCommandOutput("ifconfig wlan0");
|
||||||
--log:debug(" ifconfig: \n"..utils.dump(ifconfig));
|
--log:verbose(" ifconfig: \n"..utils.dump(ifconfig));
|
||||||
local localip = ifconfig:match('inet addr:([%d\.]+)')
|
|
||||||
return localip;
|
local localip = ifconfig:match('inet addr:([%d%.]+)')
|
||||||
|
return localip
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.getDeviceName()
|
function M.getDeviceName()
|
||||||
@ -241,7 +242,7 @@ function M.createConfigFromScanInfo(info, passphrase, disabled)
|
|||||||
uci:foreach('wireless', 'wifi-iface', function(s)
|
uci:foreach('wireless', 'wifi-iface', function(s)
|
||||||
--if s.bssid == info.bssid then
|
--if s.bssid == info.bssid then
|
||||||
if s.ssid == info.ssid then
|
if s.ssid == info.ssid then
|
||||||
log:debug("removing old wireless config for net '" .. s.ssid .. "'")
|
log:verbose("removing old wireless config for net '" .. s.ssid .. "'")
|
||||||
uci:delete('wireless', s['.name'])
|
uci:delete('wireless', s['.name'])
|
||||||
-- return false --keep looking, just in case multiple entries with this bssid exist
|
-- return false --keep looking, just in case multiple entries with this bssid exist
|
||||||
end
|
end
|
||||||
|
@ -194,7 +194,7 @@ function M.print_POST(request, response)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if argIsFirst == true then
|
if argIsFirst == true then
|
||||||
log:debug("clearing all gcode for " .. printer:getId())
|
log:verbose("clearing all gcode for " .. printer:getId())
|
||||||
response:addData('gcode_clear',true)
|
response:addData('gcode_clear',true)
|
||||||
local rv,msg = printer:clearGcode()
|
local rv,msg = printer:clearGcode()
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ function M._global_POST(request, response)
|
|||||||
local sketchIdx = listSize > 0 and sketches[listSize] + 1 or 1
|
local sketchIdx = listSize > 0 and sketches[listSize] + 1 or 1
|
||||||
local sketchFile = M.SKETCH_DIR .. '/' .. constructSketchFilename(sketchIdx)
|
local sketchFile = M.SKETCH_DIR .. '/' .. constructSketchFilename(sketchIdx)
|
||||||
|
|
||||||
log:debug("saving sketch #" .. sketchIdx .. " (" .. argData:len() .. " bytes)")
|
log:verbose("saving sketch #" .. sketchIdx .. " (" .. argData:len() .. " bytes)")
|
||||||
local saveFile,msg = io.open(sketchFile, 'w')
|
local saveFile,msg = io.open(sketchFile, 'w')
|
||||||
|
|
||||||
if not saveFile then
|
if not saveFile then
|
||||||
|
@ -167,7 +167,8 @@ setmetatable(M, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
--This function initializes itself using various environment variables, the arg array and the given postData
|
--This function initializes itself using various environment variables, the arg array and the given postData
|
||||||
--NOTE: if debugging is enabled, commandline arguments 'm' and 'f' override requested module and function
|
--NOTE: if debugging is enabled, commandline argument 'p' (path) overrides requested module and function and
|
||||||
|
-- 'r' (rqType) overrides request method
|
||||||
function M.new(environment, postData, debugEnabled)
|
function M.new(environment, postData, debugEnabled)
|
||||||
local self = setmetatable({}, M)
|
local self = setmetatable({}, M)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ local settings = require('util.settings')
|
|||||||
local defaults = require('conf_defaults')
|
local defaults = require('conf_defaults')
|
||||||
local utils = require('util.utils')
|
local utils = require('util.utils')
|
||||||
local log = require('util.logger')
|
local log = require('util.logger')
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
M.__index = M
|
M.__index = M
|
||||||
|
|
||||||
@ -167,10 +167,10 @@ function M:send()
|
|||||||
io.write("\r\n")
|
io.write("\r\n")
|
||||||
io.write(self.binaryData)
|
io.write(self.binaryData)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.body.status ~= "success" then
|
if self.body.status ~= "success" then
|
||||||
log:debug("Response:"..utils.dump(self.body.status).." ("..utils.dump(self.body.msg)..")")
|
log:verbose("Response:"..utils.dump(self.body.status).." ("..utils.dump(self.body.msg)..")")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Sets the response object to return binary data instead of JSON as its body.
|
--- Sets the response object to return binary data instead of JSON as its body.
|
||||||
|
@ -82,7 +82,7 @@ local baseUrl = M.DEFAULT_BASE_URL -- default, can be overwritten by M.setBaseUr
|
|||||||
-- @string msg The message to log.
|
-- @string msg The message to log.
|
||||||
local function P(lvl, msg)
|
local function P(lvl, msg)
|
||||||
if log then
|
if log then
|
||||||
if lvl == -1 then log:debug(msg)
|
if lvl == -1 then log:verbose(msg)
|
||||||
elseif lvl == 0 or lvl == 1 then log:info(msg)
|
elseif lvl == 0 or lvl == 1 then log:info(msg)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -90,7 +90,7 @@ local function P(lvl, msg)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Log a debug message, this function wraps @{P}.
|
--- Log a debug/verbose message, this function wraps @{P}.
|
||||||
-- The message will be logged with level -1 and be prefixed with '(DBG)'.
|
-- The message will be logged with level -1 and be prefixed with '(DBG)'.
|
||||||
-- @string msg The message to log.
|
-- @string msg The message to log.
|
||||||
local function D(msg) P(-1, (log and msg or "(DBG) " .. msg)) end
|
local function D(msg) P(-1, (log and msg or "(DBG) " .. msg)) end
|
||||||
|
@ -13,30 +13,31 @@ local utils = require('util.utils')
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local logLevel, logVerbose, logStream
|
local logLevel, logVerboseFmt, logStream
|
||||||
|
|
||||||
--- Available log levels
|
--- Available log levels (starting at 1)
|
||||||
-- @table LEVEL
|
-- @table LEVEL
|
||||||
M.LEVEL = {
|
M.LEVEL = {
|
||||||
'debug', -- for debug messages
|
'quiet', -- not used for logging, only for setting levels
|
||||||
'info', -- for informational messages
|
'error', -- fatal or non-fatal error condition
|
||||||
'warn', -- for warnings (something is wrong/fishy but not neccesarily problematic)
|
'warning', -- possibly troublesome situation
|
||||||
'error', -- for recoverable errors
|
'info', -- information about what the application is doing
|
||||||
'fatal' -- for unrecoverable errors
|
'verbose', -- extra trail information on what the application is doing
|
||||||
|
'bulk' -- debug information (in large amounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
-- M.LEVEL already has idx=>name entries, now create name=>idx entries
|
-- M.LEVEL already has idx=>name entries, now create name=>idx entries so it can be indexed both ways
|
||||||
for i,v in ipairs(M.LEVEL) do
|
for i,v in ipairs(M.LEVEL) do
|
||||||
M.LEVEL[v] = i
|
M.LEVEL[v] = i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function log(level, msg, verbose)
|
local function log(level, msg, verboseFmt)
|
||||||
if level >= logLevel then
|
if level <= logLevel then
|
||||||
local now = os.date('%m-%d %H:%M:%S')
|
local now = os.date('%m-%d %H:%M:%S')
|
||||||
local i = debug.getinfo(3) --the stack frame just above the logger call
|
local i = debug.getinfo(3) --the stack frame just above the logger call
|
||||||
local v = verbose
|
local v = verboseFmt
|
||||||
if v == nil then v = logVerbose end
|
if v == nil then v = logVerboseFmt end
|
||||||
local name = i.name or "(nil)"
|
local name = i.name or "(nil)"
|
||||||
local vVal = 'nil'
|
local vVal = 'nil'
|
||||||
local m = (type(msg) == 'string') and msg or utils.dump(msg)
|
local m = (type(msg) == 'string') and msg or utils.dump(msg)
|
||||||
@ -52,21 +53,30 @@ end
|
|||||||
--- Initializes the logger.
|
--- Initializes the logger.
|
||||||
-- @tparam @{util.logger.LEVEL} level Minimum level of messages to log.
|
-- @tparam @{util.logger.LEVEL} level Minimum level of messages to log.
|
||||||
-- @tparam bool verbose Write verbose log messages (include file/line inforomation).
|
-- @tparam bool verbose Write verbose log messages (include file/line inforomation).
|
||||||
function M:init(level, verbose)
|
function M:init(level, verboseFmt)
|
||||||
logLevel = level or M.LEVEL.warn
|
logLevel = level or M.LEVEL.warning
|
||||||
logVerbose = verbose or false
|
logVerboseFmt = verboseFmt or false
|
||||||
logStream = stream or io.stdout
|
logStream = stream or io.stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M:setLevel(level, verboseFmt)
|
||||||
|
logLevel = level or M.LEVEL.warning
|
||||||
|
logVerboseFmt = verboseFmt or false
|
||||||
|
end
|
||||||
|
|
||||||
-- pass nil as stream to reset to stdout
|
-- pass nil as stream to reset to stdout
|
||||||
function M:setStream(stream)
|
function M:setStream(stream)
|
||||||
logStream = stream or io.stdout
|
logStream = stream or io.stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:debug(msg, verbose) log(M.LEVEL.debug, msg, verbose); return true end
|
function M:getLevel()
|
||||||
function M:info(msg, verbose) log(M.LEVEL.info, msg, verbose); return true end
|
return logLevel, logVerboseFmt
|
||||||
function M:warn(msg, verbose) log(M.LEVEL.warn, msg, verbose); return true end
|
end
|
||||||
function M:error(msg, verbose) log(M.LEVEL.error, msg, verbose); return false end
|
|
||||||
function M:fatal(msg, verbose) log(M.LEVEL.fatal, msg, verbose); return false end
|
function M:error(msg, verboseFmt) log(M.LEVEL.error, msg, verboseFmt); return false end
|
||||||
|
function M:warning(msg, verboseFmt) log(M.LEVEL.warning, msg, verboseFmt); return true end
|
||||||
|
function M:info(msg, verboseFmt) log(M.LEVEL.info, msg, verboseFmt); return true end
|
||||||
|
function M:verbose(msg, verboseFmt) log(M.LEVEL.verbose, msg, verboseFmt); return true end
|
||||||
|
function M:bulk(msg, verboseFmt) log(M.LEVEL.bulk, msg, verboseFmt); return true end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -81,7 +81,7 @@ end
|
|||||||
--returns a printer instance or nil (and sets error state on response in the latter case)
|
--returns a printer instance or nil (and sets error state on response in the latter case)
|
||||||
function M.createPrinterOrFail(deviceId, response)
|
function M.createPrinterOrFail(deviceId, response)
|
||||||
|
|
||||||
--log:debug("API:printer:createPrinterOrFail: "..utils.dump(deviceId))
|
--log:verbose("API:printer:createPrinterOrFail: "..utils.dump(deviceId))
|
||||||
local msg,printer = nil, nil
|
local msg,printer = nil, nil
|
||||||
|
|
||||||
if deviceId == nil or deviceId == "" then
|
if deviceId == nil or deviceId == "" then
|
||||||
@ -98,6 +98,8 @@ function M.createPrinterOrFail(deviceId, response)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
printer:setLocalLogLevel(log:getLevel())
|
||||||
|
|
||||||
return printer
|
return printer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user