infobox: added wifi channel, airtime and batctl nexthop (#38)

* infobox: added wifi channel, airtime and batctl nexthop

* simplify

* kill all semicolons

* update data locations

I'd suggest that channel information go under nodeinfo. Airtime and nexthop are changing variables which should go under statistics.

* filter out nodes with faulty nodeinfo

* additional nexthop key

The nexthop to the batman gateway has now been made available in gluon master where it will be called "gateway_nexthop" the "nexthop" key is also currently in use and should eventually be removed

* sidebar/node: cosmetic changes to gateway/nexthop

* remove data validity check

* move wifi helper function to sidebar/node

* cosmetics
This commit is contained in:
eberhab 2016-06-08 23:23:56 +02:00 committed by PetaByteBoy // Milan Pässler
parent 2bbdd1e077
commit f80ea1ca8f
2 changed files with 92 additions and 14 deletions

View file

@ -1,23 +1,23 @@
function get(url) {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest();
req.open('GET', url);
var req = new XMLHttpRequest()
req.open('GET', url)
req.onload = function() {
if (req.status == 200) {
resolve(req.response);
resolve(req.response)
}
else {
reject(Error(req.statusText));
reject(Error(req.statusText))
}
}
};
req.onerror = function() {
reject(Error("Network Error"));
};
reject(Error("Network Error"))
}
req.send();
});
req.send()
})
}
function getJSON(url) {
@ -75,7 +75,7 @@ function localStorageTest() {
function listReplace(s, subst) {
for (key in subst) {
var re = new RegExp(key, 'g');
var re = new RegExp(key, 'g')
s = s.replace(re, subst[key])
}
return s
@ -149,8 +149,8 @@ function attributeEntry(el, label, value) {
function createIframe(opt, width, height) {
el = document.createElement("iframe")
width = typeof width !== 'undefined' ? width : '525px';
height = typeof height !== 'undefined' ? height : '350px';
width = typeof width !== 'undefined' ? width : '525px'
height = typeof height !== 'undefined' ? height : '350px'
if (opt.src)
el.src = opt.src
@ -180,7 +180,7 @@ function createIframe(opt, width, height) {
function showStat(o, subst) {
var content, caption
subst = typeof subst !== 'undefined' ? subst : {};
subst = typeof subst !== 'undefined' ? subst : {}
if (o.thumbnail) {
content = document.createElement("img")

View file

@ -81,6 +81,54 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
return d.firstseen.fromNow(true)
}
function wifiChannelAlias(ch) {
var chlist = {
"1": "2412 MHz",
"2": "2417 MHz",
"3": "2422 MHz",
"4": "2427 MHz",
"5": "2432 MHz",
"6": "2437 MHz",
"7": "2442 MHz",
"8": "2447 MHz",
"9": "2452 MHz",
"10": "2457 MHz",
"11": "2462 MHz",
"12": "2467 MHz",
"13": "2472 MHz",
"36": "5180 MHz (Indoors)",
"40": "5200 MHz (Indoors)",
"44": "5220 MHz (Indoors)",
"48": "5240 MHz (Indoors)",
"52": "5260 MHz (Indoors/DFS/TPC)",
"56": "5280 MHz (Indoors/DFS/TPC)",
"60": "5300 MHz (Indoors/DFS/TPC)",
"64": "5320 MHz (Indoors/DFS/TPC)",
"100": "5500 MHz (DFS) !!",
"104": "5520 MHz (DFS) !!",
"108": "5540 MHz (DFS) !!",
"112": "5560 MHz (DFS) !!",
"116": "5580 MHz (DFS) !!",
"120": "5600 MHz (DFS) !!",
"124": "5620 MHz (DFS) !!",
"128": "5640 MHz (DFS) !!",
"132": "5660 MHz (DFS) !!",
"136": "5680 MHz (DFS) !!",
"140": "5700 MHz (DFS) !!"
}
if (!(ch in chlist))
return ""
else
return chlist[ch]
}
function showWifiChannel(ch) {
if (!ch)
return undefined
return ch + " (" + wifiChannelAlias(ch) + ")"
}
function showClients(d) {
if (!d.flags.online)
return undefined
@ -180,6 +228,32 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
}
}
function showAirtime(band, val) {
if (!val)
return undefined
return function (el) {
el.appendChild(showBar("airtime" + band.toString(), val))
}
}
function showGateway(d) {
var nh
if (dictGet(d.statistics, ["nexthop"]))
nh = dictGet(d.statistics, ["nexthop"])
if (dictGet(d.statistics, ["gateway_nexthop"]))
nh = dictGet(d.statistics, ["gateway_nexthop"])
var gw = dictGet(d.statistics, ["gateway"])
if (gw && !nh)
return gw
if (gw && nh)
if (gw === nh)
return gw
else
return nh + " -> ... -> " + gw
}
function showPages(d) {
var webpages = dictGet(d.nodeinfo, ["pages"])
if (webpages === null)
@ -248,11 +322,15 @@ define(["moment", "numeral", "tablesort", "tablesort.numeric"],
attributeEntry(attributes, "Site", showSite(d, config))
attributeEntry(attributes, "Uptime", showUptime(d))
attributeEntry(attributes, "Teil des Netzes", showFirstseen(d))
attributeEntry(attributes, "Kanal 2.4 GHz", showWifiChannel(dictGet(d.nodeinfo, ["wireless", "chan2"])))
attributeEntry(attributes, "Kanal 5 GHz", showWifiChannel(dictGet(d.nodeinfo, ["wireless", "chan5"])))
attributeEntry(attributes, "Airtime 2.4 GHz", showAirtime(2, dictGet(d.statistics, ["wireless", "airtime2"])))
attributeEntry(attributes, "Airtime 5 GHz", showAirtime(5, dictGet(d.statistics, ["wireless", "airtime5"])))
attributeEntry(attributes, "Systemlast", showLoad(d))
attributeEntry(attributes, "Arbeitsspeicher", showRAM(d))
attributeEntry(attributes, "IP Adressen", showIPs(d))
attributeEntry(attributes, "Webseite", showPages(d))
attributeEntry(attributes, "Gewähltes Gateway", dictGet(d.statistics, ["gateway"]))
attributeEntry(attributes, "Gewähltes Gateway", showGateway(d))
attributeEntry(attributes, "Autom. Updates", showAutoupdate(d))
attributeEntry(attributes, "Clients", showClients(d))