mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
Merge branch 'master' into feature/printerdriver
This commit is contained in:
commit
70d88fc036
1
Makefile
1
Makefile
@ -99,6 +99,7 @@ define Package/wifibox/install
|
||||
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/wifibox_init $(1)/etc/init.d/wifibox # copy directly to init dir (required for post-inst enabling)
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/d3dapi $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||
$(INSTALL_BIN) $(WIFIBOX_BASE_DIR)/script/signin.sh $(1)/$(TGT_LUA_DIR_SUFFIX)/script
|
||||
|
||||
$(CP) $(WIFIBOX_BASE_DIR)/script/wifibox.uci.config $(1)/etc/config/wifibox # copy base configuration to uci config dir
|
||||
|
||||
|
@ -50,6 +50,14 @@ M.network_ap_netmask = {
|
||||
regex = '%d+\.%d+\.%d+\.%d+'
|
||||
}
|
||||
|
||||
M.network_cl_wifiboxid = {
|
||||
default = 'Doodle3D-%%MAC_ADDR_TAIL%%',
|
||||
type = 'string',
|
||||
description = 'Client mode WiFi box id',
|
||||
min = 1,
|
||||
max = 32
|
||||
}
|
||||
|
||||
M.printer_type = {
|
||||
default = 'ultimaker',
|
||||
type = 'string',
|
||||
|
14
src/main.lua
14
src/main.lua
@ -8,6 +8,7 @@ local wifi = require('network.wlanconfig')
|
||||
local netconf = require('network.netconfig')
|
||||
local RequestClass = require('rest.request')
|
||||
local ResponseClass = require('rest.response')
|
||||
local Signin = require('network.signin')
|
||||
|
||||
local postData = nil
|
||||
|
||||
@ -172,6 +173,19 @@ local function main(environment)
|
||||
else
|
||||
log:error("autowifi setup failed (" .. msg .. ")")
|
||||
end
|
||||
elseif rq:getRequestMethod() == 'CMDLINE' and rq:get('signin') ~= nil then
|
||||
log:info("running in signin mode")
|
||||
|
||||
local ds = wifi.getDeviceState()
|
||||
if ds.mode == "sta" then
|
||||
local rv,msg = Signin.signin()
|
||||
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()))
|
||||
|
30
src/network/signin.lua
Normal file
30
src/network/signin.lua
Normal file
@ -0,0 +1,30 @@
|
||||
local log = require('util.logger')
|
||||
local utils = require('util.utils')
|
||||
local uci = require('uci').cursor()
|
||||
local iwinfo = require('iwinfo')
|
||||
local settings = require('util.settings')
|
||||
local wifi = require("network.wlanconfig")
|
||||
|
||||
local M = {}
|
||||
|
||||
--- Signin to connect.doodle3d.com server
|
||||
--
|
||||
function M.signin()
|
||||
local baseurl = "http://connect.doodle3d.com/signin.php"
|
||||
|
||||
local localip = wifi.getLocalIP();
|
||||
if localip == nil then
|
||||
log:error("signin failed no local ip found")
|
||||
return false
|
||||
end
|
||||
|
||||
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
||||
|
||||
local cmd = "wget -q -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
||||
local output = utils.captureCommandOutput(cmd);
|
||||
log:info("signin: "..output)
|
||||
|
||||
return string.len(output) > 0
|
||||
end
|
||||
|
||||
return M
|
@ -113,6 +113,13 @@ function M.getMacAddress()
|
||||
return out:upper()
|
||||
end
|
||||
|
||||
--returns the wireless local ip address
|
||||
function M.getLocalIP()
|
||||
local ifconfig, rv = utils.captureCommandOutput("ifconfig wlan0");
|
||||
local localip = ifconfig:match('inet addr:([%d\.]+)')
|
||||
return localip;
|
||||
end
|
||||
|
||||
function M.getDeviceName()
|
||||
return deviceName
|
||||
end
|
||||
|
@ -1,6 +1,7 @@
|
||||
local log = require('util.logger')
|
||||
local settings = require('util.settings')
|
||||
local printer = require('util.printer')
|
||||
local signin = require('network.signin')
|
||||
|
||||
local M = {
|
||||
isApi = true
|
||||
@ -26,6 +27,10 @@ function M._global_POST(request, response)
|
||||
else response:addData(k, "could not set key ('" .. m .. "')")
|
||||
end
|
||||
end
|
||||
|
||||
log:info("API:Network:try signing in")
|
||||
signin.signin();
|
||||
log:info("API:Network:signed in")
|
||||
end
|
||||
|
||||
function M.all_GET(request, response)
|
||||
|
@ -1,8 +1,10 @@
|
||||
local log = require('util.logger')
|
||||
local settings = require('util.settings')
|
||||
local utils = require('util.utils')
|
||||
local netconf = require('network.netconfig')
|
||||
local wifi = require('network.wlanconfig')
|
||||
local ResponseClass = require('rest.response')
|
||||
local signin = require('network.signin')
|
||||
|
||||
local M = {
|
||||
isApi = true
|
||||
@ -88,6 +90,9 @@ function M.status(request, response)
|
||||
response:addData("signal", ds.signal)
|
||||
response:addData("noise", ds.noise)
|
||||
if withRaw then response:addData("_raw", utils.dump(ds)) end
|
||||
|
||||
local localip = wifi.getLocalIP()
|
||||
response:addData("localip", localip)
|
||||
end
|
||||
|
||||
--requires ssid(string), accepts phrase(string), recreate(bool)
|
||||
@ -105,10 +110,12 @@ function M.associate_POST(request, response)
|
||||
return
|
||||
end
|
||||
|
||||
local associate = function()
|
||||
local rv,msg = netconf.associateSsid(argSsid, argPhrase, argRecreate)
|
||||
local associate = function()
|
||||
local rv,msg = netconf.associateSsid(argSsid, argPhrase, argRecreate)
|
||||
end
|
||||
response:addPostResponseFunction(associate)
|
||||
response:addPostResponseFunction(associate)
|
||||
|
||||
|
||||
|
||||
--[[local helloA = function()
|
||||
local log = require('util.logger')
|
||||
@ -169,4 +176,15 @@ function M.remove_POST(request, response)
|
||||
end
|
||||
end
|
||||
|
||||
function M.signin(request, response)
|
||||
log:info("API:Network:signin")
|
||||
if signin.signin() then
|
||||
log:info("API:Network:signed in")
|
||||
response:setSuccess("API:Network:signed in")
|
||||
else
|
||||
log:info("API:Network:Signing in failed")
|
||||
response:setError("Signing in failed")
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
@ -1,18 +1,9 @@
|
||||
local utils = require('util.utils')
|
||||
|
||||
local M = {
|
||||
isApi = true
|
||||
}
|
||||
|
||||
|
||||
-- TODO: this function has been duplicated from test/test_wlanconfig.lua
|
||||
local function captureCommandOutput(cmd)
|
||||
local f = assert(io.popen(cmd, 'r'))
|
||||
local output = assert(f:read('*all'))
|
||||
--TODO: test if this works to obtain the return code (http://stackoverflow.com/questions/7607384/getting-return-status-and-program-output)
|
||||
--local rv = assert(f:close())
|
||||
--return output,rv[3]
|
||||
return output
|
||||
end
|
||||
|
||||
function M._global(request, response)
|
||||
response:setSuccess()
|
||||
end
|
||||
@ -24,13 +15,13 @@ function M.fwversions(request, response)
|
||||
|
||||
response:setSuccess()
|
||||
|
||||
output = captureCommandOutput(opkg .. ' list-installed wifibox')
|
||||
output = utils.captureCommandOutput(opkg .. ' list-installed wifibox')
|
||||
local version = output:match('^wifibox %- (.*)\n$')
|
||||
response:addData('current', version)
|
||||
|
||||
rv = os.execute(opkg .. ' update >/dev/null')
|
||||
if rv == 0 then
|
||||
output = captureCommandOutput(opkg .. ' list wifibox')
|
||||
output = utils.captureCommandOutput(opkg .. ' list wifibox')
|
||||
local versions = {}
|
||||
for v in output:gmatch('wifibox %- (%d+\.%d+\.%d+%-%d+) %- ') do
|
||||
versions[#versions+1] = v
|
||||
|
@ -175,7 +175,7 @@ function M.new(environment, postData, debugEnabled)
|
||||
self.pathArgs = arrayFromPath(environment['PATH_INFO'])
|
||||
|
||||
-- override path arguments with command line parameter and allow to emulate GET/POST if debugging is enabled *and* if the autowifi special command wasn't mentioned
|
||||
if debugEnabled and self.requestMethod == 'CMDLINE' and self:get('autowifi') == nil then
|
||||
if debugEnabled and self.requestMethod == 'CMDLINE' and self:get('autowifi') == nil and self:get('signin') == nil then
|
||||
self.pathArgs = arrayFromPath(self.cmdLineArgs['p'])
|
||||
|
||||
if self.cmdLineArgs['r'] == 'GET' or self.cmdLineArgs['r'] == nil then
|
||||
|
8
src/script/signin.sh
Executable file
8
src/script/signin.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
sleep 5s
|
||||
while true; do
|
||||
/usr/share/lua/wifibox/script/d3dapi signin > /dev/null 2> /dev/null
|
||||
|
||||
sleep 1h
|
||||
done
|
@ -8,6 +8,9 @@ LOGGER="logger -s -t autowifi -p 6"
|
||||
boot() {
|
||||
$LOGGER "Invoking Doodle3D WiFi box network auto-initialization..."
|
||||
/usr/share/lua/wifibox/script/d3dapi autowifi
|
||||
|
||||
$LOGGER "Start signing in..."
|
||||
/usr/share/lua/wifibox/script/signin.sh > /dev/null 2> /dev/null &
|
||||
}
|
||||
|
||||
#start() {
|
||||
@ -16,4 +19,4 @@ boot() {
|
||||
|
||||
#stop() {
|
||||
# $LOGGER "dummy stop"
|
||||
#}
|
||||
#}
|
@ -97,20 +97,31 @@ end
|
||||
----------------------------------------------------------------------------
|
||||
function _M.parsequeryNoRegex (query, args)
|
||||
if type(query) == "string" then
|
||||
local log = require('util.logger')
|
||||
local util = require('util.utils')
|
||||
log:info("parsequeryNoRegex")
|
||||
--log:info(" query: " .. util.dump(query))
|
||||
--log:info(" args: " .. util.dump(args))
|
||||
|
||||
local insertfield, unescape = _M.insertfield, _M.unescape
|
||||
|
||||
local k = 1
|
||||
while true do
|
||||
local v = query:find('=', k+1, true) -- look for '=', assuming a key of at least 1 character and do not perform pattern matching
|
||||
--log:info(" v: " .. util.dump(v))
|
||||
if not v then break end -- no k/v pairs left
|
||||
|
||||
local key = query:sub(k, v-1)
|
||||
log:info(" key: " .. util.dump(key))
|
||||
v = v + 1
|
||||
--log:info(" >v: " .. util.dump(v))
|
||||
local ampersand = query:find('&', v, true)
|
||||
--log:info(" ampersand: " .. util.dump(ampersand))
|
||||
if not ampersand then ampersand = 0 end -- 0 will become -1 in the substring call below...meaning end of string
|
||||
|
||||
|
||||
local value = query:sub(v, ampersand - 1)
|
||||
--log:info(" value: " .. util.dump(value))
|
||||
insertfield (args, unescape(key), unescape(value))
|
||||
|
||||
if ampersand == 0 then break end -- we couldn't find any ampersands anymore so this was the last k/v
|
||||
|
@ -103,4 +103,12 @@ function M.readFile(filePath)
|
||||
return res
|
||||
end
|
||||
|
||||
-- TODO: this function has been duplicated from rest/api/api_system.lua
|
||||
function M.captureCommandOutput(cmd)
|
||||
local f = assert(io.popen(cmd, 'r'))
|
||||
local output = assert(f:read('*all'))
|
||||
f:close()
|
||||
return output;
|
||||
end
|
||||
|
||||
return M
|
||||
|
Loading…
Reference in New Issue
Block a user