mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 19:13:49 +01:00
added localip to /d3dapi/network/status (centralized captureCommandOutput and getLocalIP)
This commit is contained in:
parent
d5a2c2cad9
commit
6a4879c7b2
@ -3,37 +3,28 @@ local utils = require('util.utils')
|
|||||||
local uci = require('uci').cursor()
|
local uci = require('uci').cursor()
|
||||||
local iwinfo = require('iwinfo')
|
local iwinfo = require('iwinfo')
|
||||||
local settings = require('util.settings')
|
local settings = require('util.settings')
|
||||||
local wlanconfig = require("network.wlanconfig")
|
local wifi = require("network.wlanconfig")
|
||||||
|
|
||||||
local M = {}
|
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
|
--- Signin to connect.doodle3d.com server
|
||||||
--
|
--
|
||||||
function M.signin()
|
function M.signin()
|
||||||
local wifiboxid = "henk"
|
log:info("signin")
|
||||||
local localip = "10.0.0.99"
|
local baseurl = "http://connect.doodle3d.com/signin.php"
|
||||||
local baseurl = "http://192.168.5.220/connect.doodle3d.local/signin.php"
|
|
||||||
|
|
||||||
local ifconfig = captureCommandOutput("ifconfig wlan0");
|
local localip = wifi.getLocalIP();
|
||||||
--log:info("ifconfig: "..ifconfig)
|
log:info("localip: "..utils.dump(localip))
|
||||||
local localip = ifconfig:match('inet addr:([%d\.]+)')
|
if localip == nil then
|
||||||
--log:info("localip: "..utils.dump(localip))
|
log:error("signin failed no local ip found")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local wifiboxid = wlanconfig.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid'))
|
||||||
--log:info("wifiboxid: "..utils.dump(wifiboxid))
|
log:info("wifiboxid: "..utils.dump(wifiboxid))
|
||||||
|
|
||||||
local cmd = "wget -q -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
local cmd = "wget -q -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip;
|
||||||
local output = captureCommandOutput(cmd);
|
local output = utils.captureCommandOutput(cmd);
|
||||||
log:info("signin: "..output)
|
log:info("signin: "..output)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -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
|
||||||
|
@ -88,6 +88,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)
|
||||||
|
@ -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
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
sleep 5s
|
||||||
while true; do
|
while true; do
|
||||||
/usr/share/lua/wifibox/script/d3dapi signin > /dev/null 2> /dev/null
|
/usr/share/lua/wifibox/script/d3dapi signin > /dev/null 2> /dev/null
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user