add WAN wifi ssid and SNR to Status page (#552)

When WAN connects via wifi to an AP, show SSID and SNR.  Added workaround to intermittent bad value strength retuned from iw, when positive value.  Assume absolute value is correct and add back a negative sign.
This commit is contained in:
Steve 2022-11-24 12:07:22 -07:00 committed by GitHub
parent cf2497b346
commit 46a23f8e26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 7 deletions

View File

@ -129,8 +129,14 @@ function get_wifi_signal(wifiif)
end
end
if signal == -1000 or noise == -1000 then
return "N/A", "N/A"
return "none", "none"
else
if signal > 0 then
signal = (0 - signal)
end
if noise > 0 then
noise = (0 - noise)
end
return signal, noise
end
end
@ -157,6 +163,7 @@ local config = aredn_info.get_nvram("config")
if config == "" or nixio.fs.stat("/etc/config.mesh", "type") ~= "dir" then
config = "not set"
end
local wifi_iface = aredn.hardware.get_iface_name("wifi")
local wifi_nr = wifi_iface:match("wlan(%d+)")
local wifi_disabled = true
@ -177,7 +184,7 @@ if not wifi_disabled then
wifi_channel = wifi_channel * 5 + 3000
end
wifi_chanbw = cursor:get("wireless", radio, "chanbw")
wifi_ssid = "N/A"
wifi_ssid = "none"
cursor:foreach("wireless", "wifi-iface",
function (section)
if section.network == "wifi" then
@ -340,14 +347,44 @@ local wan_iface = aredn.hardware.get_iface_name("wan")
if not hide_local and wan_iface then
local ip, bcast, mask = aredn.hardware.get_interface_ip4(wan_iface)
local wprefix = ""
local wan_wifi_sig = "none"
local wan_wifi_noi = "none"
local wan_wifi_snr = "none"
if wan_iface:match("^wlan%d+$") then
wprefix = "WiFi "
wprefix = "wifi "
local s, n = get_wifi_signal(wan_iface)
if s ~= "none" and n ~= "none" then
wan_wifi_sig = s
wan_wifi_noi = n
wan_wifi_snr = math.abs(s - n)
end
end
local wan_wifi_ssid
cursor:foreach("wireless", "wifi-iface",
function (section)
if section.network == "wan" then
wan_wifi_ssid = section.ssid
return false
end
end
)
if not wan_wifi_ssid then -- if still nil then set default
wan_wifi_ssid = "none"
end
if ip then
cidr = netmask_to_cidr(mask)
col1[#col1 + 1] = "<th align=right><nobr>" .. wprefix .. "WAN address:</nobr></th><td>" .. ip .. " <small>/ " .. cidr .. "</small><br>"
if wprefix == "" then
col1[#col1 + 1] = "<th align=right><nobr>WAN address:</nobr><br><nobr>" .. "</th><td>" .. ip .. " <small>/ " .. cidr .. "</small></td>"
else
if wan_wifi_ssid ~= "none" and wan_wifi_snr ~= "none" then
col1[#col1 + 1] = "<th align=right><nobr>" .. wprefix .. "WAN address:</nobr><br><nobr>" .. wprefix .. "WAN SSID / SNR:</nobr></th><td>" .. ip .. " <small>/ " .. cidr .. "</small><br><nobr>" .. wan_wifi_ssid .. " / " .. wan_wifi_snr .. " dB</td>"
else
col1[#col1 + 1] = "<th align=right><nobr>" .. wprefix .. "WAN address:</nobr></th><td>" .. ip .. " <small>/ " .. cidr .. "</small></td>"
end
end
else
col1[#col1 + 1] = "<th align=right><nobr>" .. wprefix .. "WAN address:</nobr></th><td>none</small><br>"
col1[#col1 + 1] = "<th align=right><nobr>WAN address:</nobr></th><td>none</small></td>"
end
end
@ -368,9 +405,9 @@ end
-- right column - system info
if config == "mesh" and not wifi_disabled then
col2[#col2 + 1] = "<th align=right valign=middle><nobr>signal / noise / ratio:</nobr></th><td valign=middle><nobr>"
col2[#col2 + 1] = "<th align=right valign=middle><nobr>signal / noise / SNR:</nobr></th><td valign=middle><nobr>"
local s, n = get_wifi_signal(wifi_iface)
if s == "N/A" then
if s == "none" then
col2[#col2] = col2[#col2] .. "no RF links"
else
col2[#col2] = col2[#col2] .. "<big><b>" .. s .. " / " .. n .. " / " .. math.abs(s - n) .. " dB</b></big>"