mirror of https://github.com/aredn/aredn.git
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:
parent
b4c5691110
commit
afe30ffc6e
|
@ -47,6 +47,7 @@ end
|
||||||
local wifiiface = aredn.hardware.get_iface_name("wifi")
|
local wifiiface = aredn.hardware.get_iface_name("wifi")
|
||||||
local phy = iwinfo.nl80211.phyname(wifiiface)
|
local phy = iwinfo.nl80211.phyname(wifiiface)
|
||||||
local rfband = aredn.hardware.get_rfband()
|
local rfband = aredn.hardware.get_rfband()
|
||||||
|
local nf = iwinfo.nl80211.noise(wifiiface) or -95
|
||||||
|
|
||||||
if not nixio.fs.stat("/tmp/web") then
|
if not nixio.fs.stat("/tmp/web") then
|
||||||
nixio.fs.mkdir("/tmp/web")
|
nixio.fs.mkdir("/tmp/web")
|
||||||
|
@ -189,7 +190,7 @@ html.print("<button type=button onClick='window.location=\"status\"' title='Retu
|
||||||
|
|
||||||
-- display scan
|
-- display scan
|
||||||
html.print("<table class=sortable border=1 cellpadding=5>")
|
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
|
-- load arp cache
|
||||||
local arpcache = {}
|
local arpcache = {}
|
||||||
|
@ -248,7 +249,7 @@ do
|
||||||
else
|
else
|
||||||
html.print("<tr>")
|
html.print("<tr>")
|
||||||
end
|
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>")
|
html.print("</tr>")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -260,7 +261,7 @@ local cheight = 400;
|
||||||
html.print([[
|
html.print([[
|
||||||
<center style="font-family: Arial">
|
<center style="font-family: Arial">
|
||||||
<div style="padding:8px">Spectral View</div>
|
<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>
|
<canvas id="spectral" width="]] .. cwidth .. [[" height="]] .. cheight .. [[" style="border:1px solid grey;background-color:white"></canvas>
|
||||||
<div style="padding:4px">Channel</div>
|
<div style="padding:4px">Channel</div>
|
||||||
</center>
|
</center>
|
||||||
|
@ -273,7 +274,7 @@ function u8tos8(b)
|
||||||
return b >= 128 and b - 256 or b
|
return b >= 128 and b - 256 or b
|
||||||
end
|
end
|
||||||
|
|
||||||
local nf = iwinfo.nl80211.noise(wifiiface) or -95
|
local cnf = nf - 17.5 -- sub-carrier noise floor
|
||||||
local start_freq
|
local start_freq
|
||||||
local end_freq
|
local end_freq
|
||||||
if rfband == "900" then
|
if rfband == "900" then
|
||||||
|
@ -305,7 +306,7 @@ end
|
||||||
bw = tonumber(bw) or 10
|
bw = tonumber(bw) or 10
|
||||||
|
|
||||||
local xscale = cwidth / (end_freq - start_freq)
|
local xscale = cwidth / (end_freq - start_freq)
|
||||||
local min_sig = nf
|
local min_sig = cnf
|
||||||
local max_sig = -60
|
local max_sig = -60
|
||||||
local i = 1
|
local i = 1
|
||||||
html.write("const p = [")
|
html.write("const p = [")
|
||||||
|
@ -320,31 +321,29 @@ do
|
||||||
local rssi = u8tos8(samples:byte(i + 6))
|
local rssi = u8tos8(samples:byte(i + 6))
|
||||||
local noise = u8tos8(samples:byte(i + 7))
|
local noise = u8tos8(samples:byte(i + 7))
|
||||||
local datasqsum = 0
|
local datasqsum = 0
|
||||||
local dlen = l - 18
|
|
||||||
local v = {}
|
local v = {}
|
||||||
for dptr = 0, dlen - 1
|
for dptr = 1,56
|
||||||
do
|
do
|
||||||
local data = nixio.bit.lshift(samples:byte(dptr + i + 20), max_exp)
|
local data = nixio.bit.lshift(samples:byte(dptr + i + 19), max_exp)
|
||||||
if data == 0 then
|
data = data * data
|
||||||
data = 1
|
datasqsum = datasqsum + data
|
||||||
end
|
|
||||||
datasqsum = datasqsum + data * data
|
|
||||||
v[dptr] = data
|
v[dptr] = data
|
||||||
end
|
end
|
||||||
datasqsum = math.log10(datasqsum) * 10
|
for dptr = 1,56
|
||||||
for dptr = 0, dlen - 1
|
|
||||||
do
|
do
|
||||||
local data = v[dptr]
|
local datasq = v[dptr]
|
||||||
local sig = noise + rssi + 20 * math.log10(data) - datasqsum
|
if datasq ~= 0 then
|
||||||
local fr = freq + bw * (dptr / dlen - 0.5) - start_freq
|
local sig = noise + rssi + 10 * math.log10(datasq / datasqsum)
|
||||||
if sig >= -125 then
|
local fr = freq + bw * (dptr / 56 - 0.5) - start_freq
|
||||||
if sig < min_sig then
|
if sig >= -125 then
|
||||||
min_sig = sig
|
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
|
end
|
||||||
if sig > max_sig then
|
|
||||||
max_sig = sig
|
|
||||||
end
|
|
||||||
html.write(math.floor(fr * xscale) .. "," .. math.floor(-sig * 4) .. ",")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -360,7 +359,7 @@ html.print([[
|
||||||
for (let i = 0; i < p.length; i += 2) {
|
for (let i = 0; i < p.length; i += 2) {
|
||||||
const sig = p[i+1];
|
const sig = p[i+1];
|
||||||
const idx = 4 * (p[i] + ]] .. cwidth .. [[ * Math.floor(yscale * (ytran - sig)));
|
const idx = 4 * (p[i] + ]] .. cwidth .. [[ * Math.floor(yscale * (ytran - sig)));
|
||||||
if (sig < ]] .. (-4 * nf) .. [[) {
|
if (sig < ]] .. (-4 * cnf) .. [[) {
|
||||||
d[idx] = 0;
|
d[idx] = 0;
|
||||||
d[idx+1] = 0;
|
d[idx+1] = 0;
|
||||||
d[idx+2] = 255;
|
d[idx+2] = 255;
|
||||||
|
@ -395,19 +394,18 @@ html.print([[
|
||||||
ctx.textAlign = "left";
|
ctx.textAlign = "left";
|
||||||
ctx.strokeStyle = "lightblue";
|
ctx.strokeStyle = "lightblue";
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
for (let signal = -30; signal >= -120; signal -= 10) {
|
for (let snr = 60; snr >= 0; snr -= 10) {
|
||||||
const y = Math.floor(yscale * (ytran + signal * 4));
|
const y = Math.floor(yscale * (ytran + ]] .. (cnf * 4) .. [[ + snr * 4));
|
||||||
ctx.moveTo(30, y);
|
ctx.moveTo(20, y);
|
||||||
ctx.lineTo(]] .. cwidth .. [[, y);
|
ctx.lineTo(]] .. cwidth .. [[, y);
|
||||||
ctx.fillText("" + signal, 2, y);
|
ctx.fillText("" + snr, 2, y);
|
||||||
}
|
}
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
ctx.strokeStyle = "blue";
|
ctx.strokeStyle = "blue";
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
const y = Math.floor(yscale * (]] .. (nf * 4) .. [[ + ytran));
|
const y = Math.floor(yscale * (]] .. (cnf * 4) .. [[ + ytran));
|
||||||
ctx.moveTo(30, y);
|
ctx.moveTo(30, y);
|
||||||
ctx.lineTo(]] .. cwidth .. [[, y);
|
ctx.lineTo(]] .. cwidth .. [[, y);
|
||||||
ctx.fillText("NF", 4, y);
|
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
</script></form>
|
</script></form>
|
||||||
]])
|
]])
|
||||||
|
|
Loading…
Reference in New Issue