0
0
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:
peteruithoven 2013-10-02 15:17:08 +02:00
commit 70d88fc036
13 changed files with 122 additions and 18 deletions

View File

@ -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/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/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 $(CP) $(WIFIBOX_BASE_DIR)/script/wifibox.uci.config $(1)/etc/config/wifibox # copy base configuration to uci config dir

View File

@ -50,6 +50,14 @@ M.network_ap_netmask = {
regex = '%d+\.%d+\.%d+\.%d+' 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 = { M.printer_type = {
default = 'ultimaker', default = 'ultimaker',
type = 'string', type = 'string',

View File

@ -8,6 +8,7 @@ local wifi = require('network.wlanconfig')
local netconf = require('network.netconfig') local netconf = require('network.netconfig')
local RequestClass = require('rest.request') local RequestClass = require('rest.request')
local ResponseClass = require('rest.response') local ResponseClass = require('rest.response')
local Signin = require('network.signin')
local postData = nil local postData = nil
@ -172,6 +173,19 @@ local function main(environment)
else else
log:error("autowifi setup failed (" .. msg .. ")") log:error("autowifi setup failed (" .. msg .. ")")
end 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 elseif rq:getRequestMethod() ~= 'CMDLINE' or confDefaults.DEBUG_API then
-- log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>") -- log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
-- .. "/" .. (rq:getRealApiFunctionName() or "<unknown>") .. " with arguments: " .. util.dump(rq:getAll())) -- .. "/" .. (rq:getRealApiFunctionName() or "<unknown>") .. " with arguments: " .. util.dump(rq:getAll()))

30
src/network/signin.lua Normal file
View 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

View File

@ -113,6 +113,13 @@ function M.getMacAddress()
return out:upper() return out:upper()
end 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() function M.getDeviceName()
return deviceName return deviceName
end end

View File

@ -1,6 +1,7 @@
local log = require('util.logger') local log = require('util.logger')
local settings = require('util.settings') local settings = require('util.settings')
local printer = require('util.printer') local printer = require('util.printer')
local signin = require('network.signin')
local M = { local M = {
isApi = true isApi = true
@ -26,6 +27,10 @@ function M._global_POST(request, response)
else response:addData(k, "could not set key ('" .. m .. "')") else response:addData(k, "could not set key ('" .. m .. "')")
end end
end end
log:info("API:Network:try signing in")
signin.signin();
log:info("API:Network:signed in")
end end
function M.all_GET(request, response) function M.all_GET(request, response)

View File

@ -1,8 +1,10 @@
local log = require('util.logger')
local settings = require('util.settings') local settings = require('util.settings')
local utils = require('util.utils') local utils = require('util.utils')
local netconf = require('network.netconfig') local netconf = require('network.netconfig')
local wifi = require('network.wlanconfig') local wifi = require('network.wlanconfig')
local ResponseClass = require('rest.response') local ResponseClass = require('rest.response')
local signin = require('network.signin')
local M = { local M = {
isApi = true isApi = true
@ -88,6 +90,9 @@ function M.status(request, response)
response:addData("signal", ds.signal) response:addData("signal", ds.signal)
response:addData("noise", ds.noise) response:addData("noise", ds.noise)
if withRaw then response:addData("_raw", utils.dump(ds)) end if withRaw then response:addData("_raw", utils.dump(ds)) end
local localip = wifi.getLocalIP()
response:addData("localip", localip)
end end
--requires ssid(string), accepts phrase(string), recreate(bool) --requires ssid(string), accepts phrase(string), recreate(bool)
@ -105,10 +110,12 @@ function M.associate_POST(request, response)
return return
end end
local associate = function() local associate = function()
local rv,msg = netconf.associateSsid(argSsid, argPhrase, argRecreate) local rv,msg = netconf.associateSsid(argSsid, argPhrase, argRecreate)
end end
response:addPostResponseFunction(associate) response:addPostResponseFunction(associate)
--[[local helloA = function() --[[local helloA = function()
local log = require('util.logger') local log = require('util.logger')
@ -169,4 +176,15 @@ function M.remove_POST(request, response)
end end
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 return M

View File

@ -1,18 +1,9 @@
local utils = require('util.utils')
local M = { local M = {
isApi = true 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) function M._global(request, response)
response:setSuccess() response:setSuccess()
end end
@ -24,13 +15,13 @@ function M.fwversions(request, response)
response:setSuccess() response:setSuccess()
output = captureCommandOutput(opkg .. ' list-installed wifibox') output = utils.captureCommandOutput(opkg .. ' list-installed wifibox')
local version = output:match('^wifibox %- (.*)\n$') local version = output:match('^wifibox %- (.*)\n$')
response:addData('current', version) response:addData('current', version)
rv = os.execute(opkg .. ' update >/dev/null') rv = os.execute(opkg .. ' update >/dev/null')
if rv == 0 then if rv == 0 then
output = captureCommandOutput(opkg .. ' list wifibox') output = utils.captureCommandOutput(opkg .. ' list wifibox')
local versions = {} local versions = {}
for v in output:gmatch('wifibox %- (%d+\.%d+\.%d+%-%d+) %- ') do for v in output:gmatch('wifibox %- (%d+\.%d+\.%d+%-%d+) %- ') do
versions[#versions+1] = v versions[#versions+1] = v

View File

@ -175,7 +175,7 @@ function M.new(environment, postData, debugEnabled)
self.pathArgs = arrayFromPath(environment['PATH_INFO']) 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 -- 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']) self.pathArgs = arrayFromPath(self.cmdLineArgs['p'])
if self.cmdLineArgs['r'] == 'GET' or self.cmdLineArgs['r'] == nil then if self.cmdLineArgs['r'] == 'GET' or self.cmdLineArgs['r'] == nil then

8
src/script/signin.sh Executable file
View 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

View File

@ -8,6 +8,9 @@ LOGGER="logger -s -t autowifi -p 6"
boot() { boot() {
$LOGGER "Invoking Doodle3D WiFi box network auto-initialization..." $LOGGER "Invoking Doodle3D WiFi box network auto-initialization..."
/usr/share/lua/wifibox/script/d3dapi autowifi /usr/share/lua/wifibox/script/d3dapi autowifi
$LOGGER "Start signing in..."
/usr/share/lua/wifibox/script/signin.sh > /dev/null 2> /dev/null &
} }
#start() { #start() {
@ -16,4 +19,4 @@ boot() {
#stop() { #stop() {
# $LOGGER "dummy stop" # $LOGGER "dummy stop"
#} #}

View File

@ -97,20 +97,31 @@ end
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
function _M.parsequeryNoRegex (query, args) function _M.parsequeryNoRegex (query, args)
if type(query) == "string" then 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 insertfield, unescape = _M.insertfield, _M.unescape
local k = 1 local k = 1
while true do 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 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 if not v then break end -- no k/v pairs left
local key = query:sub(k, v-1) local key = query:sub(k, v-1)
log:info(" key: " .. util.dump(key))
v = v + 1 v = v + 1
--log:info(" >v: " .. util.dump(v))
local ampersand = query:find('&', v, true) 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 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) local value = query:sub(v, ampersand - 1)
--log:info(" value: " .. util.dump(value))
insertfield (args, unescape(key), unescape(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 if ampersand == 0 then break end -- we couldn't find any ampersands anymore so this was the last k/v

View File

@ -103,4 +103,12 @@ function M.readFile(filePath)
return res return res
end 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 return M