Add more radio information to status (#1325)

This commit is contained in:
Tim Wilkinson 2024-08-19 16:28:57 -07:00 committed by GitHub
parent 3b1e7947aa
commit 53a63886d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 113 additions and 41 deletions

View File

@ -35,10 +35,19 @@
{%
const radio = radios.getActiveConfiguration();
let midx = -1;
let lidx = -1;
let widx = -1;
for (let i = 0; i < length(radio); i++) {
if (radio[i].mode === radios.RADIO_MESH) {
midx = i;
break;
switch (radio[i].mode) {
case radios.RADIO_MESH:
midx = i;
break;
case radios.RADIO_LAN:
lidx = i;
break;
case radios.RADIO_WAN:
widx = i;
break;
}
}
%}
@ -47,24 +56,28 @@
<div class="section">
<div class="t">{{hardware.getRadio().name}}</div>
<div class="s">model</div>
{% if (midx !== -1) { %}
</div>
{% if (midx !== -1) {
const r = radio[midx].modes[radios.RADIO_MESH]; %}
<div class="section-title">Mesh</div>
<div class="section">
<div class="cols">
<div>
<div class="t">{{radio[midx].modes[radios.RADIO_MESH].channel}}</div>
<div class="t">{{r.channel}}</div>
<div class="s">channel</div>
</div>
<div>
<div class="t">{{hardware.getChannelFrequencyRange(radio[midx].iface, radio[midx].modes[radios.RADIO_MESH].channel, radio[midx].modes[radios.RADIO_MESH].bandwidth)}}</div>
<div class="t">{{hardware.getChannelFrequencyRange(radio[midx].iface, r.channel, r.bandwidth)}}</div>
<div class="s">frequencies</div>
</div>
<div>
<div class="t">{{radio[midx].modes[radios.RADIO_MESH].bandwidth}} MHz</div>
<div class="t">{{r.bandwidth}} MHz</div>
<div class="s">bandwidth</div>
</div>
</div>
<div class="cols">
<div>
<div class="t">{{radio[midx].modes[radios.RADIO_MESH].txpower + radio[midx].txpoweroffset}} dBm</div>
<div class="t">{{r.txpower + radio[midx].txpoweroffset}} dBm</div>
<div class="s">tx power</div>
</div>
<div>
@ -76,8 +89,37 @@
<div class="s">minimum snr</div>
</div>
</div>
{% } %}
</div>
{% }
if (lidx !== -1) {
const r = radio[lidx].modes[radios.RADIO_LAN]; %}
<div class="section-title">LAN Hotspot</div>
<div class="section">
<div class="cols">
<div>
<div class="t">{{r.channel}}</div>
<div class="s">channel</div>
</div>
<div>
<div class="t">{{r.ssid}}</div>
<div class="s">ssid</div>
</div>
<div></div>
</div>
</div>
{% }
if (widx !== -1) {
const r = radio[widx].modes[radios.RADIO_WAN]; %}
<div class="section-title">WAN Client</div>
<div class="section">
<div class="cols">
<div>
<div class="t">{{r.ssid}}</div>
<div class="s">ssid</div>
</div>
</div>
</div>
{% } %}
{% if (midx !== -1) { %}
<div class="section-title">Antenna</div>
<div class="section">

View File

@ -148,7 +148,7 @@ export function getRfChannels(wifiIface)
let channels = channelsCache[wifiIface];
if (!channels) {
channels = [];
const f = fs.popen("/usr/bin/iwinfo " + wifiIface + " freqlist");
const f = fs.popen("/usr/sbin/iw " + replace(wifiIface, "wlan", "phy") + " info 2> /dev/null");
if (f) {
let freq_adjust = 0;
let freq_min = 0;
@ -171,11 +171,11 @@ export function getRfChannels(wifiIface)
if (!line) {
break;
}
const fn = match(line, /(\d+\.\d+) GHz \(Band: .*, Channel (-?\d+)\)/);
const fn = match(line, /(\d+) MHz \[(-?\d+)\] /);
if (fn && index(line, "restricted") == -1 && index(line, "disabled") === -1) {
const freq = int(replace(fn[1], ".", "")) + freq_adjust;
const freq = int(fn[1]) + freq_adjust;
if (freq >= freq_min && freq <= freq_max) {
const num = int(replace(fn[2], "0+", ""));
const num = int(fn[2]);
push(channels, {
label: freq_adjust === 0 ? num + " (" + freq + ")" : "" + freq,
number: num,

View File

@ -70,34 +70,64 @@ export function getActiveConfiguration()
const radio = getCommonConfiguration();
const nrradios = length(radio);
if (nrradios > 0) {
const meshrf = cursor.get("network", "wifi", "device");
const widx = match(meshrf, /^wlan(\d+)$/);
if (widx) {
let device;
const mode = {
channel: 0,
bandwidth: 10,
ssid: "AREDN",
txpower: configuration.getSettingAsInt("wifi_txpower")
};
cursor.foreach("wireless", "wifi-iface", function(s)
{
if (s.network === "wifi" && s.ifname === meshrf) {
device = s.device;
mode.ssid = s.ssid;
return false;
}
});
cursor.foreach("wireless", "wifi-device", function(s)
{
if (s[".name"] === device) {
mode.channel = int(s.channel);
mode.bandwidth = int(s.chanbw);
return false;
}
});
radio[widx[1]].mode = RADIO_MESH;
radio[widx[1]].modes = [ null, mode, null, null ];
let mdevice;
let ldevice;
let wdevice;
const mmode = {
channel: 0,
bandwidth: 10,
ssid: "-",
txpower: configuration.getSettingAsInt("wifi_txpower")
};
const lmode = {
channel: 0,
ssid: "-"
};
const wmode = {
ssid: "-"
};
cursor.foreach("wireless", "wifi-iface", function(s)
{
if (s.network === "wifi" && s.mode === "adhoc") {
mdevice = s.device;
mmode.ssid = s.ssid;
}
if (s.network === "lan" && s.mode === "ap") {
ldevice = s.device;
lmode.ssid = s.ssid;
}
if (s.network === "wan" && s.mode === "sta") {
wdevice = s.device;
wmode.ssid = s.ssid;
}
});
cursor.foreach("wireless", "wifi-device", function(s)
{
if (s[".name"] === mdevice) {
mmode.channel = int(s.channel);
mmode.bandwidth = int(s.chanbw);
}
if (s[".name"] === ldevice) {
lmode.channel = int(s.channel);
}
});
if (mdevice) {
const idx = int(substr(mdevice, 5));
radio[idx].mode = RADIO_MESH;
radio[idx].modes = [ null, mmode, null, null ];
}
if (ldevice) {
const idx = int(substr(ldevice, 5));
radio[idx].mode = RADIO_LAN;
radio[idx].modes = [ null, null, lmode, null ];
}
if (wdevice) {
const idx = int(substr(wdevice, 5));
radio[idx].mode = RADIO_WAN;
radio[idx].modes = [ null, null, null, wmode ];
}
}
return radio;