cloudy cloudy

Author Topic: Jpgraph upgrade causing script issue - issue resolved  (Read 264 times)

0 Members and 3 Guests are viewing this topic.

Offline Bonz

  • Posts: 162
  • Auburn, Mass
  • OS/Browser:
  • Win NT 10.0
  • Mozilla compatible
    • Auburn MA Weather
Jpgraph upgrade causing script issue - issue resolved
« on: April 14, 2019, 04:28:37 PM »
RESOLVED
I am trying to get my site off of php 5.6 and move to 7.2.   My JPGraph program needed to be upgraded which I have done and now at 4.2.6.  With this new release it messed up a bunch of my php scripts I use with some one wire temp sensors I have.   The script below pulls 24 hours worth of temps and plots on a graph and puts the current temp in the middle of the graph.  I get a 500 error if I run the script as is below.  However if I remove the lines of code in the second code example below, the script will run and plot the 24 hour temps in one hour increments but not display the current temp in the middle (which I removed).

Can someone look at the 2nd code example below and tell me if you see anything that is depreciated etc. that would cause the error.  Again when I remove the code in the second example from the overall script it runs fine just doesn't show the current temp in the middle of the graph like it used to. 

Thanks a lot,
John


Code: [Select]
<?php
//where are your clientraw*-files relative to where this file is
$hostloc "./";
date_default_timezone_set('America/Halifax');
include (
"jp/src/jpgraph.php");           //maybe you have to change this path
include ("jp/src/jpgraph_line.php");       //maybe you have to change this path

// CtoF: converts degrees Celcius to degress Farenheight
function CtoF(&$value) {
  return 
round($value = ((1.8$value) + 32),1);
// end function C_to_F

// Create the graph and specify the scale for Y-axis
$graph = new Graph(400,250,"auto",30);    
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->SetMarginColor("#191970");
$graph->img->SetAntiAliasing();

$url "http://www.auburnweatherlive.com/basementdatapull.php";   // this is the page where you get the information
$str file_get_contents($url);                                // retrieve the content of the page. This results in one single string with all the content

$str ereg_replace(" <br/>","","$str");
$str ereg_replace("X_Axis = ","","$str");                   
$str ereg_replace("Y_Axis = ","xx","$str");

$data explode("xx"$str);                                   // xx is the separator. You will get two strings in $data
$x $data[0];                                                 // first part of $data is the X_Axis data
$y $data[1];                                                 // second part of $data is the Y_Axis data

$datat explode(" "$x);                                     // make an array of $x 
$ydata explode(" "$y);                                     // make an array of $y

//create timearray for the x-axis
$n=1;
$limit=26;
putenv('TZ=Canada/Atlantic');
$time=date(" H",time());
$datat=array($time);
$x=$datat;
//what you have to add
$add=3600;
$result=strtotime(now);
for (
$n=1;$n++;)
{
$result=($result-$add);
$new=date('ga'$result);
$next=array("$new");
$datatarray_merge ($next,$datat);
if (
$n>=$limit) break;
  }
$datat=array_merge($datat,$x);

// =====================================================================================
// From here we start creating the graphs
// =====================================================================================

// Adjust the margin
$graph->img->SetMargin(40,40,20,65);

// Create the two linear plot
$lineplot=new LinePlot($ydata);

// Add the plot to the graph
$graph->Add($lineplot);

//titles
$graph->title->Set("Basement");
$graph->title->SetFont(FF_FONT1,FS_BOLD,10);
$graph->title->SetColor("white");
//$graph->xaxis->title->Set("X-title");
//$graph->yaxis->title->Set("Y-title");

//x-axis
//$graph->xaxis->title->Set("X-title");
$time=date("M j",time());
$graph->xaxis->title->Set($time);
$graph->xaxis->title->SetColor(white);
$graph->xaxis->SetFont(FF_FONT1,FS_NORMAL,4);
$graph->xaxis->SetTickLabels($datat); 
$graph->xaxis->SetTextLabelInterval(3);
$graph->xaxis->SetPos("min"); 
$graph->xaxis->SetColor("white"); 
$graph->xaxis->HideTicks(true,true); 
$graph->xgrid->Show(true);

//y-axis
$graph->yaxis->SetColor("white");
$graph->yaxis->SetLabelFormat('%0.0fįF');
$graph->yaxis->scale->SetGrace(5);
$graph->yaxis->HideTicks(true,true); 


// Set the colors for the plots
$lineplot->SetColor("red");


// Set the legends for the plots
$lineplot->SetLegend("Temperature");


// Adjust the legend position
$graph->legend->SetLayout(LEGEND_HOR);
$graph->legend->Pos(0.5,0.9,"center","center");

// copy from here
$txt2=new Text("Current Temp"); 
$txt2->SetFont(FF_VERDANAFS_BOLD,12); 
$txt2->Pos(0.5,0.5,"center","center"); 
$txt2->SetColor("royalblue4"); 
$graph->AddText($txt2); 

// Get current clientraw reading
$clientraw get_raw("${hostloc}clientraw.txt");
//$clientrawextra = get_raw("${hostloc}clientrawextra.txt");
//$clientrawdaily = get_raw ("${hostloc}clientrawdaily.txt");

//read the clientraw*-files we need
function get_raw$rawfile ) {
$rawdata = array();
$fd fopen($rawfile"r");
if (
$fd) {
$rawcontents '';
while (! 
feof ($fd) ) {
$rawcontents .= fread($fd8192);
}
fclose($fd);
$delimiter " ";
$rawdata explode ($delimiter$rawcontents);
} else {
$rawdata[0]= -9999;
}
return 
$rawdata;
}

//temp conversion===Extra temp #5 position 24======================================================================
$z=($clientraw['24']);

//$fahrenheit = $z * (212 - 32) / 100 + 32;
$fahrenheit = ($z 1.8) + 32;
$num $fahrenheit
$cut substr($num0, ((strpos($num'.')+1)+1)); 
$cut $cut "&#38;#0176;F";
// Cut the string from first character to a length of 2 past the decimal. 
// substr(cut what, start, ( (find position of decimal)+decimal itself)+spaces after decimal) ) 

$txt42=new Text("$cut"); 
$txt42->SetFont(FF_VERDANAFS_BOLD,18); 
$txt42->Pos(0.5,0.4,"center","center"); 
$txt42->SetColor("royalblue4"); 
$graph->AddText($txt42); 


// Display the graph
$graph->Stroke();

?>



If I remove this code from the above script the script runs fine just doesn't show the current temp in the middle of the graph as the code is removed.
Code: [Select]
// copy from here
$txt2=new Text("Current Temp");
$txt2->SetFont(FF_VERDANA, FS_BOLD,12);
$txt2->Pos(0.5,0.5,"center","center");
$txt2->SetColor("royalblue4");
$graph->AddText($txt2);

// Get current clientraw reading
$clientraw = get_raw("${hostloc}clientraw.txt");
//$clientrawextra = get_raw("${hostloc}clientrawextra.txt");
//$clientrawdaily = get_raw ("${hostloc}clientrawdaily.txt");

//read the clientraw*-files we need
function get_raw( $rawfile ) {
$rawdata = array();
$fd = fopen($rawfile, "r");
if ($fd) {
$rawcontents = '';
while (! feof ($fd) ) {
$rawcontents .= fread($fd, 8192);
}
fclose($fd);
$delimiter = " ";
$rawdata = explode ($delimiter, $rawcontents);
} else {
$rawdata[0]= -9999;
}
return $rawdata;
}

//temp conversion===Extra temp #5 position 24======================================================================
$z=($clientraw['24']);

//$fahrenheit = $z * (212 - 32) / 100 + 32;
$fahrenheit = ($z * 1.8) + 32;
$num = $fahrenheit;
$cut = substr($num, 0, ((strpos($num, '.')+1)+1));
$cut = $cut . "&#0176;F";
// Cut the string from first character to a length of 2 past the decimal.
// substr(cut what, start, ( (find position of decimal)+decimal itself)+spaces after decimal) )

$txt42=new Text("$cut");
$txt42->SetFont(FF_VERDANA, FS_BOLD,18);
$txt42->Pos(0.5,0.4,"center","center");
$txt42->SetColor("royalblue4");
$graph->AddText($txt42);
« Last Edit: April 16, 2019, 12:42:17 PM by Bonz »

Offline broadstairs

  • Stuart
  • Posts: 7,066
  • Broadstairs, Kent, UK
  • OS/Browser:
  • (Linux Mint)
  • Firefox 60.0
    • Broadstairs
Re: Jpgraph upgrade causing script issue
« Reply #1 on: April 14, 2019, 04:39:01 PM »
I would expect to see the error in the web server log file, can you access that to see what actual error is displayed?

Stuart

Offline Bonz

  • Posts: 162
  • Auburn, Mass
  • OS/Browser:
  • Win NT 10.0
  • Mozilla compatible
    • Auburn MA Weather
Re: Jpgraph upgrade causing script issue
« Reply #2 on: April 14, 2019, 04:57:12 PM »
All is can see is an error in Cpanel raw data error stating the file name and that it caused a 500 error.  Thatís it
« Last Edit: April 14, 2019, 05:05:38 PM by Bonz »