Merge pull request #76 from freifunk-gluon/neighours
announce neighbours using alfred/gluon-announce
This commit is contained in:
commit
653ea4a301
@ -1 +1 @@
|
|||||||
* * * * * /lib/gluon/announce/collect.lua nodeinfo | gzip | alfred -s 158; /lib/gluon/announce/collect.lua statistics | gzip | alfred -s 159
|
* * * * * /lib/gluon/announce/collect.lua nodeinfo | gzip | alfred -s 158; /lib/gluon/announce/collect.lua statistics | gzip | alfred -s 159; /lib/gluon/announce/collect.lua neighbours | gzip | alfred -s 160
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
return require('gluon.util').node_id()
|
@ -11,7 +11,7 @@ define Package/gluon-mesh-batman-adv-core
|
|||||||
SECTION:=gluon
|
SECTION:=gluon
|
||||||
CATEGORY:=Gluon
|
CATEGORY:=Gluon
|
||||||
TITLE:=Support for batman-adv meshing (core)
|
TITLE:=Support for batman-adv meshing (core)
|
||||||
DEPENDS:=+gluon-core +firewall +kmod-ipt-nathelper
|
DEPENDS:=+gluon-core +firewall +kmod-ipt-nathelper +libiwinfo-lua
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Build/Prepare
|
define Build/Prepare
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
local json = require 'luci.json'
|
||||||
|
local util = require 'luci.util'
|
||||||
|
local fs = require 'nixio.fs'
|
||||||
|
|
||||||
|
local ifname_address_cache = {}
|
||||||
|
|
||||||
|
function ifname2address(ifname)
|
||||||
|
local ifaddress
|
||||||
|
if ifname_address_cache[ifname] ~= nil then
|
||||||
|
ifaddress = ifname_address_cache[ifname]
|
||||||
|
else
|
||||||
|
ifaddress = util.trim(fs.readfile("/sys/class/net/" .. ifname .. "/address"))
|
||||||
|
ifname_address_cache[ifname] = ifaddress
|
||||||
|
end
|
||||||
|
|
||||||
|
return ifaddress
|
||||||
|
end
|
||||||
|
|
||||||
|
function batadv()
|
||||||
|
local interfaces = {}
|
||||||
|
local list = io.lines("/sys/kernel/debug/batman_adv/bat0/originators")
|
||||||
|
for line in list do
|
||||||
|
local mac1, lastseen, tq, mac2, ifname =
|
||||||
|
line:match("^([0-9a-f:]+) +(%d+%.%d+)s +%( *(%d+)%) +([0-9a-f:]+) +%[ *(.-)%]")
|
||||||
|
|
||||||
|
if mac1 ~= nil and mac1 == mac2 then
|
||||||
|
ifaddress = ifname2address(ifname)
|
||||||
|
if interfaces[ifaddress] == nil then
|
||||||
|
interfaces[ifaddress] = { neighbours = {} }
|
||||||
|
end
|
||||||
|
|
||||||
|
interfaces[ifaddress].neighbours[mac1] = { tq = tonumber(tq)
|
||||||
|
, lastseen = tonumber(lastseen)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return interfaces
|
||||||
|
end
|
||||||
|
|
||||||
|
return batadv()
|
@ -0,0 +1,41 @@
|
|||||||
|
local json = require 'luci.json'
|
||||||
|
local util = require 'luci.util'
|
||||||
|
local fs = require 'nixio.fs'
|
||||||
|
local iwinfo = require 'iwinfo'
|
||||||
|
|
||||||
|
function neighbours(iface)
|
||||||
|
local stations = {}
|
||||||
|
for k, v in pairs(iface.iw.assoclist(iface.ifname)) do
|
||||||
|
stations[k:lower()] = { signal = v.signal
|
||||||
|
, noise = v.noise
|
||||||
|
, inactive = v.inactive
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return stations
|
||||||
|
end
|
||||||
|
|
||||||
|
function interfaces()
|
||||||
|
local interfaces = {}
|
||||||
|
for _, line in ipairs(util.split(util.exec('batctl if'))) do
|
||||||
|
ifname = line:match('^(.-): active')
|
||||||
|
if ifname ~= nil then
|
||||||
|
pcall(function()
|
||||||
|
local address = util.trim(fs.readfile('/sys/class/net/' .. ifname .. '/address'))
|
||||||
|
local wifitype = iwinfo.type(ifname)
|
||||||
|
if wifitype ~= nil then
|
||||||
|
interfaces[address] = { ifname = ifname, iw = iwinfo[wifitype] }
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return interfaces
|
||||||
|
end
|
||||||
|
|
||||||
|
local wifi = {}
|
||||||
|
for address, iface in pairs(interfaces()) do
|
||||||
|
wifi[address] = { neighbours = neighbours(iface) }
|
||||||
|
end
|
||||||
|
|
||||||
|
return wifi
|
Loading…
Reference in New Issue
Block a user