Radmon -> Google Gauge visualization

More
5 years 7 months ago #4369 by ZschorlRad
Sorry, was my mistake.
Look again the script. I have changed the end.

Please Log in or Create an account to join the conversation.

More
5 years 7 months ago #4370 by pilovis
No way, with php5 it does not work, tested on two different servers, Debian and Ubuntu.
Was it coded for php7?

Please Log in or Create an account to join the conversation.

More
5 years 7 months ago - 5 years 7 months ago #4371 by pilovis
first of all, your URLs are wrong:
$url = " www.radmon.org/radmon.php?function=lastreading&user=$user ";
should be:
$url = "http://www.radmon.org/radmon.php?function=lastreading&user=$user";
the same for the others.

Anyway, it still doesn't work, I think you made some mistakes coding this piece of script, please correct it, test it and post it again.

Thanks.
Last edit: 5 years 7 months ago by pilovis.

Please Log in or Create an account to join the conversation.

More
5 years 7 months ago #4372 by ZschorlRad
The code with some changed things:

<?php
$user = "xxxxxxx"; // change to your user name
$warning = "0.3";
$alert = "0.85";
$size = "150";

$url = "http://www.radmon.org/radmon.php?function=lastreading&user=$user";
$page = fopen($url, 'r');
$content = "";
while( !feof( $page ) ) {
$buffer = trim( fgets( $page, 4096 ) );
$content .= $buffer;
}

$startcpm = "";
$endcpm = " CPM";
preg_match( "/$startcpm(.*)$endcpm/s", $content, $match);
$cpm = $match[1];
$usvh = round($cpm/175.43, 4);   //convert CPM to uSv/h (175.43 is for SBM-20 tube), change to your GM tube
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><?php echo "Google Gauge - $user"; ?></title>
<meta name="robots" content="noindex,follow">
<meta name="googlebot" content="nosnippet,noarchive">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Expires" CONTENT="-1">
<meta http-equiv="refresh" content="120">

<style type="text/css">
  body { background-color: #AFC3C9; }
  #container { height: 100%; width: 100%; display: table; }
  #inner { vertical-align: middle; display: table-cell; }
  #gauge_div { width: <?php echo "$size"; ?>px; margin: 0 auto; }
.auto-style1 {
	text-align: left;
}
.auto-style2 {
	text-align: center;
	font-family: Arial, Helvetica, sans-serif;
	font-size: small;
}
.auto-style3 {
	font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", "Lucida Sans", Arial, sans-serif;
}
</style>

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>

  // maximum value for the gauge
  var max_gauge_value = 0.4;
  // name of the gauge
  var gauge_name = 'µSv/h';

  // global variables
  var chart, charts, data;

  // load the google gauge visualization
  google.load('visualization', '1', {packages:['gauge']});
  google.setOnLoadCallback(initChart);

  // display the data
  function displayData(point) {
    data.setValue(0, 0, gauge_name);
    data.setValue(0, 1, point);
    chart.draw(data, options);
  }

  // load the data
  function loadData() {
    // variable for the data point
    var p;

      p = <?php echo "$usvh"; ?>;

      // if there is a data point display it
      if (p) {
        
        displayData(p);
      };
  }

  // initialize the chart
  function initChart() {

    data = new google.visualization.DataTable();
    data.addColumn('string', 'Label');
    data.addColumn('number', 'Value');
    data.addRows(1);

    chart = new google.visualization.Gauge(document.getElementById('gauge_div'));
    options = {width: <?php echo "$size"; ?>, height: <?php echo "$size"; ?>, redFrom: <?php echo "$alert"; ?>, redTo: 1, yellowFrom: <?php echo "$warning"; ?>, yellowTo: <?php echo "$alert"; ?>, greenFrom: 0, greenTo: <?php echo "$warning"; ?>, minorTicks: 25, max: 1.000};

    loadData();

    // load new data every 120 seconds
    setInterval('loadData()', 120000);
  }

</script>

</head>

<body>
<div class="auto-style2">
	<strong><span class="auto-style3">Ortsdosisleistung (ODL)</span></strong></div>
    <div id="container">
      <div id="inner">
        <div id="gauge_div" class="auto-style1"><br></div>
      </div>
    </div>
  </body>
</html>

It's tested on my site: Radiation instrument or All instruments

I hope, it works.
The following user(s) said Thank You: pilovis

Please Log in or Create an account to join the conversation.

More
5 years 7 months ago #4373 by pilovis
now it works!

Thanks a lot!!!

Please Log in or Create an account to join the conversation.

Moderators: Gamma-Man
Time to create page: 0.182 seconds
Powered by Kunena Forum
Everything's free. Please support us by considering a donation. Log in first!
Solar powered Raspberry Pi 4 server stats: CPU 36% Memory 22% Swap 70% CPU temp=48.7'C Uptime 72 Days