Commit 4dbcde62 authored by anne munoz's avatar anne munoz Committed by Adam Wujek

www: dashboard shows live information

Dashboard shows live information dynamically without refreshing the web page each 5 seconds.
parent 5bee6ec0
<?php
/*
* Send dynamic information
*
* @author Anne M. <anne@sevensols.com>
*
*/
include 'json.php';
include 'functions.php';
$data = array();
#Obtain the temperatures using the last line of (wr-mon -w)
$temperatures=shell_exec("/wr/bin/wr_mon -w | tail -1");
$arr = split(" ", $temperatures);
$temperatures = $arr[1];
array_push($data, $temperatures);
#Obtain wr date
$wr_date = str_replace("\n","<br>", shell_exec("/wr/bin/wr_date -n get |tail -2"));
array_push($data, $wr_date);
$sfp = updateSfp();
array_push($data, $sfp);
$timing = getTimingParams();
array_push($data, $timing);
echo __json_encode($data);
function getTimingParams(){
$ports = shell_exec("/wr/bin/wr_mon -w | tail -2 | head -1");
$ports = explode(" ", $ports);
$txt = $ports;
return $txt;
}
function updateSfp(){
ob_start();
draw_table();
$txt = ob_get_contents();
ob_end_clean();
return $txt;
}
?>
......@@ -31,4 +31,5 @@ $_SESSION['LAST_ACTIVITY'] = time();
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/jquery-3.1.1.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
<script type="text/javascript" src="js/loadinfo.js"></script>
</head>
var datainfo;
get_info();
var interval = setInterval(get_info, 5000);
function get_info(){
try{
$.ajax({
url: "getinfo.php",
type: "POST",
data: "data",
success: function (data) {
datainfo = JSON.parse(data);
if($("#sfp_panel").length > 0)
updateValues();
else
clearInterval(interval);
},
error: function () {
clearInterval(interval);
}
}); // AJAX Get
}
catch(err){
console.log(err);
}
}
function updateValues(){
$("#sfp_panel").html(datainfo[2]);
$("#temp").text(datainfo[0]);
$("#datewr").html(datainfo[1]);
var status;
var end = false;
for (var i=0; i<datainfo[3].length-1 && !end; i++){
var content = datainfo[3][i];
if (content.indexOf("sv")>-1){
//datainfo[3][i] = '<b>' + content + '<b><br/>';
if (content.indexOf("0")>-1) {
datainfo[3][i+1] = 'UNDEFINED' + '<br/>';//modify next line
status = datainfo[3][i+1];
}
else{
datainfo[3][i+1] = datainfo[3][i+1].replace("ss:", "");
datainfo[3][i+1] = datainfo[3][i+1].replace("\'", "");
datainfo[3][i+1] = datainfo[3][i+1].replace("\'", "");
datainfo[3][i+1] = datainfo[3][i+1] ;
status = datainfo[3][i+1];
}
end=true; //jump to next state
}
}
$("#timing").html(status);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment