These are the latest scripts. You also need the following libraries present in the directory with the scripts. Search in Google and download from the Web:
jquery-1.11.0.min.js
jquery.csv-0.71.js
This is the script to call from the "Actions" section of the controller Settings page. Adjust the paths to the log file (as3935_log.txt) and text display file (as3935_display.txt) to suit the local path on the machine running the Apache web server - log_as3935.php:
<?php
$date = date("m/d/Y");
$time = date("G:i:s");
$datetime = "$date $time";
# Retrieve all possible value names and values from Controller on strike event for testing and save to file.
# $file_test = fopen("/volume1/web/as3935_test.txt","w");
# foreach ($_GET as $key => $value)
# {
# fwrite($file_test,"$key: $value\n");
# }
# fclose($file_test);
$strokes = $_GET['strokes'];
$disturbers = $_GET['disturbers'];
$duration = $_GET['duration'];
#$rate = $strokes;
if ($duration <= 60) {
($rate = 0);
} else {
$rate = round(($strokes/$duration*60),2);
}
$dist = $_GET['dist'];
$dist_min = $_GET['dist_min'];
$dist_max = $_GET['dist_max'];
$energy = $_GET['energy'];
$energy_min = $_GET['energy_min'];
$energy_max = $_GET['energy_max'];
$strokes_all = $_GET['strokes_all'];
$disturbers_all = $_GET['disturbers_all'];
$events = $_GET['events'];
if (!file_exists("/volume1/web/as3935_log.txt")) {
$file = fopen("/volume1/web/as3935_log.txt","w");
fwrite($file,"Date,Time,Date-Time,Event Strokes,Event Disturbers,Event Duration,Event Strike Rate,Current Strike Distance,Event Min Distance,Event Max Distance,Current Strike Energy,Event Min Energy,Event Max Energy,All Strokes,All Disturbers,Events\n");
fclose($file);
}
$file = fopen("/volume1/web/as3935_log.txt","a");
fwrite($file,"$date,$time,$datetime,$strokes,$disturbers,$duration,$rate,$dist,$dist_min,$dist_max,$energy,$energy_min,$energy_max,$strokes_all,$disturbers_all,$events\n");
fclose($file);
$file2 = fopen("/volume1/web/as3935_display.txt","w");
fwrite($file2,"\nLast Strike\n==== ======\nLatest Strike:.................$date $time\nLatest Strike Distance:........$dist KM\nLatest Strike Energy:..........$energy\n\nLast Event\n==== =====\nNumber of Strikes in Event:....$strokes\nLightning Event Duration:......$duration Seconds\nCurrent Event Strike Rate:.....$rate Strikes/Minute\nShortest Distance to Strike:...$dist_min KM\nLongest Distance to Strike:....$dist_max KM\nLowest Strike Intensity:.......$energy_min\nHighest Strike Intensity:......$energy_max\nTotal strikes since reboot:....$strokes_all\n");
fclose($file2);
?>
This is the .html that reads the as3935_log.txt CSV file and displays the Distance graph - as3935_distance.html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="60">
<title>AS3935 Distance</title>
<script src="https://www.google.com/jsapi"></script>
<script src="./jquery-1.11.0.min.js"></script>
<script src="./jquery.csv-0.71.js"></script>
<script>
// load the visualization library from Google and set a listener
google.load("visualization", "1", {packages:["corechart"]});
// next line prevents caching of retrieved data by IE and possibly other browsers.
// without this, IE11 never updated the graphs on new strike data being added to the .csv file.
$.ajaxSetup({ cache: false });
google.setOnLoadCallback(drawChart);
function drawChart() {
// grab the CSV
$.get("as3935_log.txt", function(csvString) {
// transform the CSV string into a 2-dimensional array
var arrayData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar});
// this new DataTable object holds all the data
var data = new google.visualization.arrayToDataTable(arrayData);
//Use rowRange variable to set the last "n" number of rows of data to display
var rowRange = 300;
var numRows = data.getNumberOfRows();
var maxRows = numRows-1;
var minRows = numRows-rowRange;
if (minRows < 0){minRows = 0;}
// this view can select a subset of the data at a time
var view = new google.visualization.DataView(data);
view.setColumns([2,7]);
view.setRows(minRows,maxRows);
var options = {
title: "AS3935 Lightning Distance in KM\nLast 300 Strikes",
chartArea: {height: 120, width: 1000},
backgroundColor: {fill: "#33CCFF"},
hAxis: {title: data.getColumnLabel(2), slantedText: 1, slantedTextAngle: 45, textStyle: {fontSize: 10}},
//vAxis: {title: data.getColumnLabel(7), minValue: data.getColumnRange(7).min, maxValue: data.getColumnRange(7).max},
vAxis: {title: data.getColumnLabel(7)},
legend: 'none'
};
var chart1 = new google.visualization.ColumnChart(document.getElementById('chart1'));
chart1.draw(view, options);
});
}
</script>
</head>
<body>
<div id="chart1" style="width:1100px; height:325px;"> </div>
</body>
</html>
This is the .html that reads the as3935_log.txt CSV file and displays the Energy graph - as3935_energy.html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="60" >
<title>AS3935 Energy</title>
<script src="https://www.google.com/jsapi"></script>
<script src="./jquery-1.11.0.min.js"></script>
<script src="./jquery.csv-0.71.js"></script>
<script>
// load the visualization library from Google and set a listener
google.load("visualization", "1", {packages:["corechart"]});
// next line prevents caching of retrieved data by IE and possibly other browsers.
// without this, IE11 never updated the graphs on new strike data being added to the .csv file.
$.ajaxSetup({ cache: false });
google.setOnLoadCallback(drawChart);
function drawChart() {
// grab the CSV
$.get("as3935_log.txt", function(csvString) {
// transform the CSV string into a 2-dimensional array
var arrayData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar});
// this new DataTable object holds all the data
var data = new google.visualization.arrayToDataTable(arrayData);
//Use rowRange variable to set the last "n" number of rows of data to display
var rowRange = 300;
var numRows = data.getNumberOfRows();
var maxRows = numRows-1;
var minRows = numRows-rowRange;
if (minRows < 0){minRows = 0;}
// this view can select a subset of the data at a time
var view = new google.visualization.DataView(data);
view.setColumns([2,10]);
view.setRows(minRows,maxRows);
var options = {
title: "AS3935 Lightning Energy - Unitless\nLast 300 Strikes",
chartArea: {height: 120, width: 900},
backgroundColor: {fill: "#33CCFF"},
hAxis: {title: data.getColumnLabel(2), slantedText: 1, slantedTextAngle: 45, textStyle: {fontSize: 10}},
//vAxis: {title: data.getColumnLabel(10), minValue: data.getColumnRange(10).min, maxValue: data.getColumnRange(10).max},
vAxis: {title: data.getColumnLabel(10)},
legend: 'none'
};
var chart2 = new google.visualization.ColumnChart(document.getElementById('chart2'));
chart2.draw(view, options);
});
}
</script>
</head>
<body>
<div id="chart2" style="width:1100px; height:325px;">
</div>
</body>
</html>
This is the .html that reads the as3935_log.txt CSV file and displays the Rate graph - as3935_rate.html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="60" >
<title>AS3935 Rate</title>
<script src="https://www.google.com/jsapi"></script>
<script src="./jquery-1.11.0.min.js"></script>
<script src="./jquery.csv-0.71.js"></script>
<script>
// load the visualization library from Google and set a listener
google.load("visualization", "1", {packages:["corechart"]});
// next line prevents caching of retrieved data by IE and possibly other browsers.
// without this, IE11 never updated the graphs on new strike data being added to the .csv file.
$.ajaxSetup({ cache: false });
google.setOnLoadCallback(drawChart);
function drawChart() {
// grab the CSV
$.get("as3935_log.txt", function(csvString) {
// transform the CSV string into a 2-dimensional array
var arrayData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar});
// this new DataTable object holds all the data
var data = new google.visualization.arrayToDataTable(arrayData);
//Use rowRange variable to set the last "n" number of rows of data to display
var rowRange = 300;
var numRows = data.getNumberOfRows();
var maxRows = numRows-1;
var minRows = numRows-rowRange;
if (minRows < 0){minRows = 0;}
// this view can select a subset of the data at a time
var view = new google.visualization.DataView(data);
view.setColumns([2,6]);
view.setRows(minRows,maxRows);
var options = {
title: "AS3935 Lightning Event Strike Rate\nStrikes/Minute\nLast 300 Strikes",
chartArea: {height: 120, width: 900},
backgroundColor: {fill: "#33CCFF"},
hAxis: {title: data.getColumnLabel(2), slantedText: 1, slantedTextAngle: 45, textStyle: {fontSize: 10}},
//vAxis: {title: data.getColumnLabel(6), minValue: data.getColumnRange(6).min, maxValue: data.getColumnRange(6).max},
vAxis: {title: data.getColumnLabel(6)},
legend: 'none'
};
var chart3 = new google.visualization.ColumnChart(document.getElementById('chart3'));
chart3.draw(view, options);
});
}
</script>
</head>
<body>
<div id="chart3" style="width:1100px; height:325px;">
</div>
</body>
</html>
This html formats the as3935_display.txt for proper display on a web page. It must have a .php suffix - display_as3935_data.php:
<html>
<head>
<meta http-equiv="refresh" content="5" >
</head>
<body bgcolor="#33CCFF">
<?php
echo "<p> <b> <font face='courier'>";
echo nl2br(file_get_contents("as3935_display.txt"));
echo "</font> </b> </p>";
?>
</body>
</html>
This ties it all together on a single web page - as3935_stats.html:
<!DOCTYPE html>
<html>
<head>
</head>
<body bgcolor="#FFFFCC">
<center>
<p><b><font size="5" color="blue">AS3935 Local Lightning Detection Module Statistics</font></b></p>
<p><b>Text updates every 5 seconds. Graphs upate every minute. Times in US Central local time.</b></p>
<p>The AS3935 chip-based detector module detects local lightning strikes independently of the primary Blitzortung hardware, although
the Blitzortung controller communicates with the module and gathers data for each detected strike. The
chip on the board performs detection, distance estimates to the leading edge of the storm front, and a measure
of relative energy received for each strike. The module does not provide direction or position information.</p>
<iframe src="display_as3935_data.php" height=335 width=545 scrolling=no frameborder=0> margin=auto display=block align=middle</iframe></br>
<iframe src="as3935_distance.html" height=335 width=1125 scrolling=no frameborder=0 margin=auto display=block></iframe>
<iframe src="as3935_energy.html" height=335 width=1125 scrolling=no frameborder=0 margin=auto display=block></iframe>
<iframe src="as3935_rate.html" height=335 width=1125 scrolling=no frameborder=0 margin=auto display=block></iframe>
</center>
</body>
</html>
Regards,
Don