Graph in SNR + fixes (#412)

Feedback from Joe and others to adjust the noise floor (which is lower
for subchannels). Label with SNR because that's easier to compare to the
SNR values people are already familiar with.
This commit is contained in:
Tim Wilkinson 2022-06-25 18:45:28 -07:00 committed by GitHub
parent b4c5691110
commit afe30ffc6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 31 deletions

View File

@ -47,6 +47,7 @@ end
local wifiiface = aredn.hardware.get_iface_name("wifi")
local phy = iwinfo.nl80211.phyname(wifiiface)
local rfband = aredn.hardware.get_rfband()
local nf = iwinfo.nl80211.noise(wifiiface) or -95
if not nixio.fs.stat("/tmp/web") then
nixio.fs.mkdir("/tmp/web")
@ -189,7 +190,7 @@ html.print("<button type=button onClick='window.location=\"status\"' title='Retu
-- display scan
html.print("<table class=sortable border=1 cellpadding=5>")
html.print("<tr><th>Sig</th><th>Chan</th><th>Enc</th><th>SSID</th><th>Hostname</th><th>MAC/BSSID</th><th>802.11 Mode</th></tr>")
html.print("<tr><th>SNR</th><th>Signal</th><th>Chan</th><th>Enc</th><th>SSID</th><th>Hostname</th><th>MAC/BSSID</th><th>802.11 Mode</th></tr>")
-- load arp cache
local arpcache = {}
@ -248,7 +249,7 @@ do
else
html.print("<tr>")
end
html.print("<td>" .. scan.signal .. "</td><td>" .. chan .. "</td><td>" .. scan.key .. "</td><td>" .. scan.ssid .. "</td><td align=center>" .. hostname .. "</td><td>" .. scan.mac:upper() .. "</td><td>" .. scan.mode .. "</td>")
html.print("<td>" .. (scan.signal - nf) .. "</td><td>" .. scan.signal .. "</td><td>" .. chan .. "</td><td>" .. scan.key .. "</td><td>" .. scan.ssid .. "</td><td align=center>" .. hostname .. "</td><td>" .. scan.mac:upper() .. "</td><td>" .. scan.mode .. "</td>")
html.print("</tr>")
end
@ -260,7 +261,7 @@ local cheight = 400;
html.print([[
<center style="font-family: Arial">
<div style="padding:8px">Spectral View</div>
<div style="position:relative;display:inline-block"><div style="position:absolute;left:-34px;top:-200px;transform:rotate(-90deg)">Signal</div></div>
<div style="position:relative;display:inline-block"><div style="position:absolute;left:-30px;top:-200px;transform:rotate(-90deg)">SNR</div></div>
<canvas id="spectral" width="]] .. cwidth .. [[" height="]] .. cheight .. [[" style="border:1px solid grey;background-color:white"></canvas>
<div style="padding:4px">Channel</div>
</center>
@ -273,7 +274,7 @@ function u8tos8(b)
return b >= 128 and b - 256 or b
end
local nf = iwinfo.nl80211.noise(wifiiface) or -95
local cnf = nf - 17.5 -- sub-carrier noise floor
local start_freq
local end_freq
if rfband == "900" then
@ -305,7 +306,7 @@ end
bw = tonumber(bw) or 10
local xscale = cwidth / (end_freq - start_freq)
local min_sig = nf
local min_sig = cnf
local max_sig = -60
local i = 1
html.write("const p = [")
@ -320,31 +321,29 @@ do
local rssi = u8tos8(samples:byte(i + 6))
local noise = u8tos8(samples:byte(i + 7))
local datasqsum = 0
local dlen = l - 18
local v = {}
for dptr = 0, dlen - 1
for dptr = 1,56
do
local data = nixio.bit.lshift(samples:byte(dptr + i + 20), max_exp)
if data == 0 then
data = 1
end
datasqsum = datasqsum + data * data
local data = nixio.bit.lshift(samples:byte(dptr + i + 19), max_exp)
data = data * data
datasqsum = datasqsum + data
v[dptr] = data
end
datasqsum = math.log10(datasqsum) * 10
for dptr = 0, dlen - 1
for dptr = 1,56
do
local data = v[dptr]
local sig = noise + rssi + 20 * math.log10(data) - datasqsum
local fr = freq + bw * (dptr / dlen - 0.5) - start_freq
if sig >= -125 then
if sig < min_sig then
min_sig = sig
local datasq = v[dptr]
if datasq ~= 0 then
local sig = noise + rssi + 10 * math.log10(datasq / datasqsum)
local fr = freq + bw * (dptr / 56 - 0.5) - start_freq
if sig >= -125 then
if sig < min_sig then
min_sig = sig
end
if sig > max_sig then
max_sig = sig
end
html.write(math.floor(fr * xscale) .. "," .. math.floor(-sig * 4) .. ",")
end
if sig > max_sig then
max_sig = sig
end
html.write(math.floor(fr * xscale) .. "," .. math.floor(-sig * 4) .. ",")
end
end
end
@ -360,7 +359,7 @@ html.print([[
for (let i = 0; i < p.length; i += 2) {
const sig = p[i+1];
const idx = 4 * (p[i] + ]] .. cwidth .. [[ * Math.floor(yscale * (ytran - sig)));
if (sig < ]] .. (-4 * nf) .. [[) {
if (sig < ]] .. (-4 * cnf) .. [[) {
d[idx] = 0;
d[idx+1] = 0;
d[idx+2] = 255;
@ -395,19 +394,18 @@ html.print([[
ctx.textAlign = "left";
ctx.strokeStyle = "lightblue";
ctx.beginPath();
for (let signal = -30; signal >= -120; signal -= 10) {
const y = Math.floor(yscale * (ytran + signal * 4));
ctx.moveTo(30, y);
for (let snr = 60; snr >= 0; snr -= 10) {
const y = Math.floor(yscale * (ytran + ]] .. (cnf * 4) .. [[ + snr * 4));
ctx.moveTo(20, y);
ctx.lineTo(]] .. cwidth .. [[, y);
ctx.fillText("" + signal, 2, y);
ctx.fillText("" + snr, 2, y);
}
ctx.stroke();
ctx.strokeStyle = "blue";
ctx.beginPath();
const y = Math.floor(yscale * (]] .. (nf * 4) .. [[ + ytran));
const y = Math.floor(yscale * (]] .. (cnf * 4) .. [[ + ytran));
ctx.moveTo(30, y);
ctx.lineTo(]] .. cwidth .. [[, y);
ctx.fillText("NF", 4, y);
ctx.stroke();
</script></form>
]])