From 94bcea894efc693f15710aab0000627b7d248532 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Wed, 16 Oct 2013 20:31:59 +0200 Subject: [PATCH 01/12] Longer delay for access point create stability --- src/script/wifibox_init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/wifibox_init b/src/script/wifibox_init index d766af6..27bd4bd 100755 --- a/src/script/wifibox_init +++ b/src/script/wifibox_init @@ -6,7 +6,7 @@ START=22 LOGGER="logger -s -t autowifi -p 6" boot() { - sleep 1 + sleep 5 $LOGGER "Invoking Doodle3D WiFi box network auto-initialization..." /usr/share/lua/wifibox/script/d3dapi autowifi From f4babb5c2079a7fe771ec690b6c3b4717e3e060c Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Wed, 16 Oct 2013 20:32:27 +0200 Subject: [PATCH 02/12] More API:network/openap logs --- src/network/netconfig.lua | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/network/netconfig.lua b/src/network/netconfig.lua index 4222720..1b129f0 100644 --- a/src/network/netconfig.lua +++ b/src/network/netconfig.lua @@ -260,7 +260,7 @@ end -- @return True on success or nil+msg on error. function M.setupAccessPoint(ssid) - M.setStatus(M.CREATING,"Creating access point..."); + M.setStatus(M.CREATING,"Creating access point '"..ssid.."'..."); M.switchConfiguration{apnet="add_noreload"} wifi.activateConfig(ssid) @@ -269,7 +269,24 @@ function M.setupAccessPoint(ssid) M.switchConfiguration{dhcp="reload"} M.setStatus(M.CREATED,"Access point created"); - + + local ds = wifi.getDeviceState() + --log:info(" network/status: ") + log:info(" ssid: ".. utils.dump(ds.ssid)) + --[[log:info(" bssid: ".. utils.dump(ds.bssid)) + log:info(" channel: ".. utils.dump(ds.channel)) + log:info(" mode: ".. utils.dump(ds.mode)) + log:info(" encryption: ".. utils.dump(ds.encryption)) + log:info(" quality: ".. utils.dump(ds.quality)) + log:info(" quality_max: ".. utils.dump(ds.quality_max)) + log:info(" txpower: ".. utils.dump(ds.txpower)) + log:info(" signal: ".. utils.dump(ds.signal)) + log:info(" noise: ".. utils.dump(ds.noise)) + log:info(" raw: ".. utils.dump(ds)) + + local localip = wifi.getLocalIP() + log:info(" localip: "..utils.dump(localip))]]-- + return true end From 1425d5ef90330d8cc7e1c27d54c1b5f67235dd98 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Thu, 17 Oct 2013 12:08:03 +0200 Subject: [PATCH 03/12] More network logging --- src/main.lua | 2 +- src/network/netconfig.lua | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.lua b/src/main.lua index 0c1a78e..0aa18e3 100644 --- a/src/main.lua +++ b/src/main.lua @@ -154,7 +154,7 @@ local function init(environment) s, msg = wifi.init() if not s then return s, msg end - s, msg = netconf.init(wifi, true) + s, msg = netconf.init(wifi, false) if not s then return s, msg end return true diff --git a/src/network/netconfig.lua b/src/network/netconfig.lua index 1b129f0..4260cab 100644 --- a/src/network/netconfig.lua +++ b/src/network/netconfig.lua @@ -76,9 +76,15 @@ function M.commitComponent(c) end function M.reloadComponent(c, silent) - log:info("reloading component '" .. c .. "'") - if silent ~= nil and silent then os.execute('/etc/init.d/' .. c .. ' reload &> /dev/null') - else os.execute('/etc/init.d/' .. c .. ' reload') end + log:info("reloading component '" .. c .. "'") + local cmd = '/etc/init.d/' .. c .. ' reload' + if silent ~= nil and silent then + cmd = cmd .. ' &> /dev/null' + os.execute(cmd) + else + rv = utils.captureCommandOutput(cmd) + log:info(" result reloading component '" .. c .. "': "..utils.dump(rv)) + end end function M.uciTableSet(config, section, options) From cd6754bfe10834a019df59851d3c54e11350d65d Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Thu, 17 Oct 2013 14:03:30 +0200 Subject: [PATCH 04/12] Added access point min max --- src/conf_defaults.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/conf_defaults.lua b/src/conf_defaults.lua index 9dedf8d..aad3c94 100644 --- a/src/conf_defaults.lua +++ b/src/conf_defaults.lua @@ -18,7 +18,7 @@ local M = {} --NOTE: pcall protects from invocation exceptions, which is what we need except --during debugging. This flag replaces them with a normal call so we can inspect stack traces. -M.DEBUG_PCALLS = false +M.DEBUG_PCALLS = true --This enables debugging of the REST API from the command-line, specify the path and optionally the request method as follows: 'p=/mod/func rq=POST' M.DEBUG_API = true @@ -44,9 +44,11 @@ M.network_ap_address = { } M.network_ap_key = { - default = '', - type = 'string', - description = 'Access Point security key' + default = '', + type = 'string', + description = 'Access Point security key', + min = 8, + max = 63 } M.network_ap_netmask = { From a85528e956bcbe4034435b38de16675427b7813b Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Thu, 17 Oct 2013 14:04:13 +0200 Subject: [PATCH 05/12] More helpfull validation errors --- src/rest/api/api_config.lua | 10 ++++++-- src/util/settings.lua | 47 +++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/rest/api/api_config.lua b/src/rest/api/api_config.lua index ba07751..48d0b72 100644 --- a/src/rest/api/api_config.lua +++ b/src/rest/api/api_config.lua @@ -1,4 +1,5 @@ local log = require('util.logger') +local utils = require('util.utils') local settings = require('util.settings') local printer = require('util.printer') local signin = require('network.signin') @@ -19,12 +20,17 @@ function M._global_GET(request, response) end function M._global_POST(request, response) + --log:info("API:config:set") response:setSuccess() for k,v in pairs(request:getAll()) do + --log:info(" "..k..": "..v); local r,m = settings.set(k, v) - if r then response:addData(k, "ok") - else response:addData(k, "could not set key ('" .. m .. "')") + if r then + response:addData(k, "ok") + else + response:addData(k, "could not save setting ('" .. m .. "')") + log:info(" m: "..utils.dump(m)) end end diff --git a/src/util/settings.lua b/src/util/settings.lua index 5d264d6..4ee1725 100644 --- a/src/util/settings.lua +++ b/src/util/settings.lua @@ -13,6 +13,8 @@ local uci = require('uci').cursor() local utils = require('util.utils') local baseconfig = require('conf_defaults') +local utils = require('util.utils') +local log = require('util.logger') local M = {} @@ -107,18 +109,25 @@ local function isValid(value, baseTable) elseif varType == 'int' or varType == 'float' then local numValue = tonumber(value) - local ok = numValue and true or false - ok = ok and (varType == 'float' or math.floor(numValue) == numValue) - if min then ok = ok and numValue >= min end - if max then ok = ok and numValue <= max end - return ok or nil,"invalid int/float value or out of range" + if numValue == nil then + return nil, "invalid number" + elseif varType == 'int' and math.floor(numValue) ~= numValue then + return nil, "invalid int" + elseif min and numValue < min then + return nil, "to low" + elseif max and numValue > max then + return nil, "to high" + end elseif varType == 'string' then local ok = true - if min then ok = ok and value:len() >= min end - if max then ok = ok and value:len() <= max end - if regex then ok = ok and value:match(regex) ~= nil end - return ok or nil,"invalid string value" + if min and value:len() < min then + return nil,"to short" + elseif max and value:len() > max then + return nil,"to long" + elseif regex and value:match(regex) == nil then + return nil,"invalid value" + end end return true @@ -191,6 +200,7 @@ end -- @treturn bool|nil True if everything went well, nil in case of error. -- @treturn ?string Error message in case first return value is nil (invalid key). function M.set(key, value) + --log:info("settings:set: "..utils.dump(key)) key = replaceDots(key) local r = utils.create(UCI_CONFIG_FILE) @@ -198,11 +208,11 @@ function M.set(key, value) local base = getBaseKeyTable(key) if not base then return nil,ERR_NO_SUCH_KEY end - + if M.isDefault(key) and value == nil then return true end -- key is default already - + --log:info(" not default") local current = uci:get(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key) - + --log:info(" base.type: "..utils.dump(base.type)) if base.type == 'bool' then if value ~= "" then value = utils.toboolean(value) @@ -216,15 +226,16 @@ function M.set(key, value) end end + + local valid,m = isValid(value, base) + if not valid then + return nil,m + end + if fromUciValue(current, base.type) == value then return true end if value ~= nil then - local valid,m = isValid(value, base) - if (valid) then - uci:set(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key, toUciValue(value, base.type)) - else - return nil,m - end + uci:set(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key, toUciValue(value, base.type)) else uci:delete(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, key) end From 72678ef1cc5665b90a45f6073df36ec0590f160f Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Thu, 17 Oct 2013 15:28:57 +0200 Subject: [PATCH 06/12] Access point key validation function and handling validation function messages in general --- src/conf_defaults.lua | 19 ++++++++++++++----- src/util/settings.lua | 5 +++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/conf_defaults.lua b/src/conf_defaults.lua index aad3c94..6049d21 100644 --- a/src/conf_defaults.lua +++ b/src/conf_defaults.lua @@ -44,11 +44,20 @@ M.network_ap_address = { } M.network_ap_key = { - default = '', - type = 'string', - description = 'Access Point security key', - min = 8, - max = 63 + default = '', + type = 'string', + description = 'Access Point security key', + isValid = function(value) + if value == "" then + return true; + elseif value:len() < 8 then + return false, "to short" + elseif value:len() > 63 then + return false, "to long" + else + return true + end + end } M.network_ap_netmask = { diff --git a/src/util/settings.lua b/src/util/settings.lua index 4ee1725..00d6e16 100644 --- a/src/util/settings.lua +++ b/src/util/settings.lua @@ -100,8 +100,9 @@ local function isValid(value, baseTable) local varType, min, max, regex, isValid = baseTable.type, baseTable.min, baseTable.max, baseTable.regex, baseTable.isValid if isValid then - local ok = isValid(value) - return ok or nil,"invalid value" + local ok,msg = isValid(value) + if msg == nil then msg = "invalid value" end + return ok or nil,msg end if varType == 'bool' then From e87641d76a743eab1172543d26bd2bb831850aab Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Thu, 17 Oct 2013 15:29:10 +0200 Subject: [PATCH 07/12] client submodule update --- src/www | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/www b/src/www index b1ded5d..b978b5a 160000 --- a/src/www +++ b/src/www @@ -1 +1 @@ -Subproject commit b1ded5d41bb4b234c0715dfdf28a54486658b393 +Subproject commit b978b5ada57ce1e6dfdb5a78957b557a3eee774f From b5465a43fd77c28895fc0312d263bfed20ab5a14 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 18 Oct 2013 12:57:28 +0200 Subject: [PATCH 08/12] return substituted ssid on save settings response --- src/rest/api/api_config.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/rest/api/api_config.lua b/src/rest/api/api_config.lua index 48d0b72..0f19a1c 100644 --- a/src/rest/api/api_config.lua +++ b/src/rest/api/api_config.lua @@ -3,6 +3,7 @@ local utils = require('util.utils') local settings = require('util.settings') local printer = require('util.printer') local signin = require('network.signin') +local wifi = require('network.wlanconfig') local M = { isApi = true @@ -22,17 +23,25 @@ end function M._global_POST(request, response) --log:info("API:config:set") response:setSuccess() + + local validation = {} for k,v in pairs(request:getAll()) do --log:info(" "..k..": "..v); local r,m = settings.set(k, v) if r then - response:addData(k, "ok") + --response:addData(k, "ok") + validation[k] = "ok" else - response:addData(k, "could not save setting ('" .. m .. "')") + --response:addData(k, "could not save setting ('" .. m .. "')") + validation[k] = "could not save setting ('" .. m .. "')" log:info(" m: "..utils.dump(m)) end end + response:addData("validation",validation) + + local substitutedSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) + response:addData("substituted_ssid",substitutedSsid) log:info("API:Network:try signing in") if signin.signin() then From d64fea433715de0e5bc67a6eb0f755ba63c7b334 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 18 Oct 2013 16:15:54 +0200 Subject: [PATCH 09/12] Using {printingTemp} and {preheatTemp} in default start and end gcode --- src/conf_defaults.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conf_defaults.lua b/src/conf_defaults.lua index 6049d21..1ff32d1 100644 --- a/src/conf_defaults.lua +++ b/src/conf_defaults.lua @@ -195,13 +195,13 @@ M.printer_enableTraveling = { } M.printer_startgcode = { - default = ';Generated with Doodle3D\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)', + default = ';Generated with Doodle3D\nM109 S{printingTemp} ;set target temperature \nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)', type = 'string', description = '' } M.printer_endgcode = { - default = 'M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S180\nM117 Done ;display message (20 characters to clear whole screen)', + default = 'M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 {preheatTemp}\nM117 Done ;display message (20 characters to clear whole screen)', type = 'string', description = '' } From 4738f8bde1eed0d3730b02ea9166bac921032d15 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 18 Oct 2013 16:16:05 +0200 Subject: [PATCH 10/12] spelling corrections --- src/conf_defaults.lua | 4 ++-- src/util/settings.lua | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/conf_defaults.lua b/src/conf_defaults.lua index 1ff32d1..d4e3e51 100644 --- a/src/conf_defaults.lua +++ b/src/conf_defaults.lua @@ -51,9 +51,9 @@ M.network_ap_key = { if value == "" then return true; elseif value:len() < 8 then - return false, "to short" + return false, "too short" elseif value:len() > 63 then - return false, "to long" + return false, "too long" else return true end diff --git a/src/util/settings.lua b/src/util/settings.lua index 00d6e16..fbb6127 100644 --- a/src/util/settings.lua +++ b/src/util/settings.lua @@ -115,17 +115,17 @@ local function isValid(value, baseTable) elseif varType == 'int' and math.floor(numValue) ~= numValue then return nil, "invalid int" elseif min and numValue < min then - return nil, "to low" + return nil, "too low" elseif max and numValue > max then - return nil, "to high" + return nil, "too high" end elseif varType == 'string' then local ok = true if min and value:len() < min then - return nil,"to short" + return nil,"too short" elseif max and value:len() > max then - return nil,"to long" + return nil,"too long" elseif regex and value:match(regex) == nil then return nil,"invalid value" end From f5030d9069cc8aa875c9007998c8cbb4e769d18c Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 18 Oct 2013 16:16:15 +0200 Subject: [PATCH 11/12] client submodule update --- src/www | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/www b/src/www index b978b5a..5ceabf4 160000 --- a/src/www +++ b/src/www @@ -1 +1 @@ -Subproject commit b978b5ada57ce1e6dfdb5a78957b557a3eee774f +Subproject commit 5ceabf41bafef6918a2ef30e74dfcb44d2938291 From 15aa89844ec052f555daf1880995649aaffde574 Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Fri, 18 Oct 2013 19:35:48 +0200 Subject: [PATCH 12/12] client submodule update --- src/www | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/www b/src/www index 5ceabf4..10724b1 160000 --- a/src/www +++ b/src/www @@ -1 +1 @@ -Subproject commit 5ceabf41bafef6918a2ef30e74dfcb44d2938291 +Subproject commit 10724b17469371570f49804a7aed5ee2c0641ce6