#!/usr/bin/perl
=for commnet
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
Copyright (C) 2015 Conrad Lara
See Contributors file for additional contributors
Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Additional Terms:
Additional use restrictions exist on the AREDN(TM) trademark and logo.
See AREDNLicense.txt for more info.
Attributions to the AREDN Project must be retained in the source code.
If importing this code into a new or existing project attribution
to the AREDN project must be added to the source code.
You must not misrepresent the origin of the material conained within.
Modified versions must be modified to attribute to the original source
and be marked in reasonable ways as differentiate it from the original
version.
=cut
$debug = 0;
BEGIN {push @INC, '/www/cgi-bin'};
use perlfunc;
# collect some variables
$node = nvram_get("node");
$node = "NOCALL" unless $node;
read_query_string();
system "mkdir -p /tmp/web";
system "rm -f /tmp/web/siglevel" if $parms{start};
# get the current levels
($s, $n) = get_wifi_signal(get_interface("wifi"));
if($s eq "N/A") { $s = $n = "---" }
# load the previous levels
if(open(FILE, "/tmp/web/siglevel"))
{
chomp($count = );
chomp($last_start = );
chomp($lineS = );
chomp($lineN = );
chomp($lineR = );
close(FILE);
@listS = split / /, $lineS;
@listN = split / /, $lineN;
@listR = split / /, $lineR;
push @listS, $s;
push @listN, $n;
if($count == 20)
{
shift @listS;
shift @listN;
shift @listR;
}
else
{
++$count;
}
}
else
{
$count = 1;
@listS = ($s);
@listN = ($n);
$last_start = 0;
}
# gather statistics
$good = 0;
$minS = $minN = $minR = 1000;
$avgS = $avgN = 0;
$maxS = $maxN = $maxR = -1000;
for($i = 0; $i < $count; $i++)
{
$s = $listS[$i];
next if $s eq "---";
++$good;
$n = $listN[$i];
$r = $s - $n;
$minS = $s if $s < $minS;
$minN = $n if $n < $minN;
$minR = $r if $r < $minR;
$maxS = $s if $s > $maxS;
$maxN = $n if $n > $maxN;
$maxR = $r if $r > $maxR;
$avgS += $s;
$avgN += $n;
}
if($good)
{
$s = $listS[-1];
$n = $listN[-1];
$r = ($s eq "---") ? "---" : $s - $n;
$avgS = int($avgS / $good);
$avgN = int($avgN / $good);
$avgR = $avgS - $avgN;
push @listR, $avgR;
# make the graph
if($s eq "---" or ($r >= $last_start and $r <= $last_start + 30))
{
$start = $last_start;
}
else
{
$start = 10*int(($maxR + 9)/10) - 30;
while($r < $start) { $start -= 10 }
$start = 0 if $start < 0;
}
for($i = $count - 1; $i >= 0; $i--)
{
$str = " " x 30;
if($listS[$i] ne "---")
{
$r2 = $listS[$i] - $listN[$i] - $start;
if($r2 > 30)
{
$r2 = 29;
substr($str, 30, 1) = ">";
}
substr($str, 0, $r2 + 1) = "*" x ($r2 + 1) if $r2 >= 0;
substr($str, 0, 1) = "<" if $r2 < 0;
if($listR[$i] >= $start and $listR[$i] <= $start + 30)
{
substr($str, $listR[$i] - $start, 1) = "|";
}
}
push @graph, " $str\n";
}
substr($graph[0], 0, 2) = ">>";
}
else
{
$s = $n = $r = "---";
$maxS = $maxN = $maxR = "---";
$avgS = $avgN = $avgR = "---";
$minS = $minN = $minR = "---";
push @listR, "---";
$start = 0;
}
# store the level history
open(FILE, ">/tmp/web/siglevel");
print FILE "$count\n$start\n@listS\n@listN\n@listR\n";
close(FILE);
# generate the page
http_header();
html_header("$node signal strength", 0);
print "\n";
print "\n";
print "\n";
show_debug_info();
show_parse_errors();
page_footer();
print "\n";
print "