0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-12-22 11:03:48 +01:00

added localip to /d3dapi/network/status (centralized captureCommandOutput and getLocalIP)

This commit is contained in:
peteruithoven 2013-09-30 18:08:02 +02:00
parent d5a2c2cad9
commit 6a4879c7b2
6 changed files with 35 additions and 34 deletions

View File

@ -3,37 +3,28 @@ local utils = require('util.utils')
local uci = require('uci').cursor()
local iwinfo = require('iwinfo')
local settings = require('util.settings')
local wlanconfig = require("network.wlanconfig")
local wifi = require("network.wlanconfig")
local M = {}
-- TODO: this function has been duplicated from rest/api/api_system.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
--- Signin to connect.doodle3d.com server
--
function M.signin()
local wifiboxid = "henk"
local localip = "10.0.0.99"
local baseurl = "http://192.168.5.220/connect.doodle3d.local/signin.php"
log:info("signin")
local baseurl = "http://connect.doodle3d.com/signin.php"
local ifconfig = captureCommandOutput("ifconfig wlan0");
--log:info("ifconfig: "..ifconfig)
local localip = ifconfig:match('inet addr:([%d\.]+)')
--log:info("localip: "..utils.dump(localip))
local localip = wifi.getLocalIP();
log:info("localip: "..utils.dump(localip))
if localip == nil then
log:error("signin failed no local ip found")
return
end
local wifiboxid = wlanconfig.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
--log:info("wifiboxid: "..utils.dump(wifiboxid))
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
log:info("wifiboxid: "..utils.dump(wifiboxid))
local cmd = "wget -q -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
local output = captureCommandOutput(cmd);
local output = utils.captureCommandOutput(cmd);
log:info("signin: "..output)
return 0

View File

@ -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

View File

@ -88,6 +88,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)

View File

@ -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

View File

@ -1,5 +1,6 @@
#!/bin/sh
sleep 5s
while true; do
/usr/share/lua/wifibox/script/d3dapi signin > /dev/null 2> /dev/null

View File

@ -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