feature: select a device to view archived data against, enabled chart zooming/panning

This commit is contained in:
Darryl Quinn 2015-12-09 15:36:09 -06:00
parent 46c13c8c64
commit c81127f2a4
2 changed files with 51 additions and 10 deletions

View File

@ -79,6 +79,7 @@ $header = <<EOF;
\$(document).ready(function () { \$(document).ready(function () {
var MAXPOINTS=10; var MAXPOINTS=10;
var chart = new CanvasJS.Chart("chartContainer", { var chart = new CanvasJS.Chart("chartContainer", {
zoomEnabled: true,
backgroundColor: "#E7E7E7", backgroundColor: "#E7E7E7",
title: { title: {
text: "$dmode Signal to Noise" text: "$dmode Signal to Noise"
@ -114,7 +115,7 @@ $header = <<EOF;
}); // --- chart }); // --- chart
var updateArchiveChart = function () { var updateArchiveChart = function () {
\$.getJSON("/cgi-bin/signal2.json", function (result) { \$.getJSON("/cgi-bin/signal2.json?device=$parms{device}", function (result) {
chart.options.data[0].dataPoints = result[0]; chart.options.data[0].dataPoints = result[0];
chart.options.data[1].dataPoints = result[1]; chart.options.data[1].dataPoints = result[1];
chart.render(); chart.render();
@ -122,11 +123,7 @@ $header = <<EOF;
}; };
var updateRealtimeChart = function () { var updateRealtimeChart = function () {
\$.getJSON("/cgi-bin/signal2.json?realtime=1", function (result) { \$.getJSON("/cgi-bin/signal2.json?realtime=1&device=$parms{device}", function (result) {
//if (dps[0].length > MAXPOINTS) {
// dps[0].shift();
// dps[1].shift();
//}
dps[0].push(result[0][0]); dps[0].push(result[0][0]);
dps[1].push(result[1][0]); dps[1].push(result[1][0]);
chart.render(); chart.render();
@ -156,6 +153,42 @@ $page = <<EOF;
</div> </div>
<h1><big>$node</big></h1><hr> <h1><big>$node</big></h1><hr>
<nobr> <nobr>
<div id="deviceSelector">
<form name="deviceSelector" method="GET" action="/cgi-bin/signal2">
Selected Device:&nbsp;<select name="device" onChange="this.form.submit();">
EOF
# get a list of files from /tmp/snrlog
my @files = `ls -1A /tmp/snrlog`;
$parms{device}="" if(!/$parms{device}/ ~~ @files);
# default to "Strongest Signal"
if($parms{device}) {
$page = $page . "<option value='strongest'>Strongest Signal</option>";
} else {
$page = $page . "<option selected value='strongest'>Strongest Signal</option>";
}
# iterate over each file
foreach $logfile (@files)
{
chomp($logfile);
next if($logfile eq 'strongest');
my ($dmac, $dname) = $logfile =~ /^(.*?)\-(.*)/;
$dname=$logfile if($dname eq '');
if($parms{device} eq $logfile) {
$page = $page . "<option selected value='$logfile'>$dname</option>";
} else {
$page = $page . "<option value='$logfile'>$dname</option>";
}
}
$page = $page . "</select>";
$page = $page . "<input type='hidden' name='realtime' value='1'></input>" if($parms{realtime} eq "1");
$page = $page . <<EOF;
</form>
</div>
<div id="chartContainer" style="width: 800px; height: 380px;"></div> <div id="chartContainer" style="width: 800px; height: 380px;"></div>
<button onclick="window.location.href='/cgi-bin/signal2'">Archive</button><button onclick="window.location.href='/cgi-bin/signal2?realtime=1'">Realtime</button><button onclick="window.location.href='/cgi-bin/status'">Quit</button> <button onclick="window.location.href='/cgi-bin/signal2'">Archive</button><button onclick="window.location.href='/cgi-bin/signal2?realtime=1'">Realtime</button><button onclick="window.location.href='/cgi-bin/status'">Quit</button>
</center> </center>

View File

@ -42,24 +42,32 @@ use perlfunc;
read_query_string(); read_query_string();
my $debug = 0; my $debug = 0;
my $filename="/tmp/snrlog"; my $dirname="/tmp/snrlog";
my @values; my @values;
my $counter=0; my $counter=0;
my $sjson; my $sjson;
my $njson; my $njson;
system("touch $filename") unless (-f $filename); system("mkdir $dirname") unless (-d $dirname);
if($parms{"realtime"}) { if($parms{"realtime"}) {
# ==== REALTIME DATA ===== # ==== REALTIME DATA =====
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$d = sprintf ("%02d:%02d:%02d", $hour, $min, $sec); $d = sprintf ("%02d:%02d:%02d", $hour, $min, $sec);
($s, $n) = get_wifi_signal(get_interface("wifi"));
#if($parms{device} eq '') {
($s, $n) = get_wifi_signal(get_interface("wifi"));
#}
$sjson= sprintf("{\"label\":\"%s\",\"y\":%s}",$d,$s); $sjson= sprintf("{\"label\":\"%s\",\"y\":%s}",$d,$s);
$njson= sprintf("{\"label\":\"%s\",\"y\":%s}",$d,$n); $njson= sprintf("{\"label\":\"%s\",\"y\":%s}",$d,$n);
} else { } else {
# ==== ARCHIVE DATA ===== # ==== ARCHIVE DATA =====
# --- Load the snr data into an array # --- Load the snr data into an array
if($parms{device} == '') { $parms{device}="strongest"; }
$filename=$dirname . "/" . $parms{device};
open my $fh, '<', $filename or die "Could not open file '$filename' $!"; open my $fh, '<', $filename or die "Could not open file '$filename' $!";
chomp(my @lines = <$fh>); chomp(my @lines = <$fh>);
close $fh; close $fh;