$str) { // Hour Graph $command = $rrdtool.' graph '.$rrdImgDir.$n.'_hour.png --start -3600 '. 'DEF:d='.$rrdDir.$n.'.rrd:temp:AVERAGE '. 'LINE1:d'.$color[0].':"'.$sensors[$n].'" '. 'GPRINT:d:LAST:"Temp\:%1.2lf %s" '. 'GPRINT:d:MIN:"Min\:%1.2lf %s" '. 'GPRINT:d:MAX:"Max\:%1.2lf %s" '. '-h'.$y.' -w'.$x.' -y1:2 --color GRID#dddddd --color MGRID#aaaaaa'; shell_exec($command); // Daily graph $command = $rrdtool.' graph '.$rrdImgDir.$n.'_day.png --start -160000 '. 'DEF:d='.$rrdDir.$n.'.rrd:temp:AVERAGE '. 'LINE1:d'.$color[0].':"'.$sensors[$n].'" '. 'GPRINT:d:LAST:"Temp\:%8.2lf %s" '. 'GPRINT:d:MIN:"Min\:%8.2lf %s" '. 'GPRINT:d:MAX:"Max\:%8.2lf %s" '. '-h'.$y.' -w'.$x.' -y1:2 --color GRID#dddddd --color MGRID#aaaaaa'; shell_exec($command); // Weekly graph $command = $rrdtool.' graph '.$rrdImgDir.$n.'_week.png -s -1week '. 'DEF:d='.$rrdDir.$n.'.rrd:temp:AVERAGE '. 'LINE1:d'.$color[0].':"'.$sensors[$n].'" '. 'GPRINT:d:MIN:"Min\:%8.2lf %s" '. 'GPRINT:d:MAX:"Max\:%8.2lf %s" '. '-h'.$y.' -w'.$x.' -y1:2 --color GRID#dddddd --color MGRID#aaaaaa'; shell_exec($command); // Monthly graph $command = $rrdtool.' graph '.$rrdImgDir.$n.'_month.png -s -1month '. 'DEF:d='.$rrdDir.$n.'.rrd:temp:AVERAGE '. 'LINE1:d'.$color[0].':"'.$sensors[$n].'" '. 'GPRINT:d:MIN:"Min\:%8.2lf %s" '. 'GPRINT:d:MAX:"Max\:%8.2lf %s" '. '-h'.$y.' -w'.$x.' -y1:2 --color GRID#dddddd --color MGRID#aaaaaa'; shell_exec($command); // Yearly graph $command = $rrdtool.' graph '.$rrdImgDir.$n.'_year.png -s -1year '. 'DEF:d='.$rrdDir.$n.'.rrd:temp:AVERAGE '. 'LINE1:d'.$color[0].':"'.$sensors[$n].'" '. 'GPRINT:d:MIN:"Min\:%8.2lf %s" '. 'GPRINT:d:MAX:"Max\:%8.2lf %s" '. '-h'.$y.' -w'.$x.' -y1:2 --color GRID#dddddd --color MGRID#aaaaaa'; shell_exec($command); } // Create a graph with all sensors, one graph for each time frame. $commands_all = array("hour"=>"--start -3600","day"=>"--start -160000","week"=>"-s -1week","month"=>"-s -1month","year"=>"-s -1year"); foreach ($commands_all as $name=>$time) { $command = $rrdtool.' graph '.$rrdImgDir.'all_'.$name.'.png '.$time.' '; foreach ($sensors as $n=>$str) { $command .= 'DEF:d'.$n.'='.$rrdDir.$n.'.rrd:temp:AVERAGE '; } foreach ($sensors as $n=>$str) { $command .= 'LINE1:d'.$n.$color[$n].':"'.$str.'" '; } $command .= '-h'.$y.' -w'.$x.' -y1:2 --color GRID#dddddd --color MGRID#aaaaaa'; shell_exec($command); } // Make index.html $index = '

Temperature sensors


'; $index .= '
'; // add "all" to the sensors list, so an index file for the combined graph is automatically created. $sensors['all'] = "All sensors"; foreach ($sensors as $n=>$str) { $index .= '
'; $index .= ''; $index .= ''; $index .= '
'.$str.'

'; } $index .= '
'; $fp = fopen($rrdImgDir."index.html","w"); fwrite ($fp,$index); fclose ($fp); // Make a HTML file fore each sensor. foreach ($sensors as $n=>$str) { $index = '

'.$str.'


'; $index .= ''; $index .= ''; $index .= ''; $index .= '
'; $index .= ''; $index .= '
Hour

'; $index .= ''; $index .= ''; $index .= '
Day

'; $index .= ''; $index .= '
Week

'; $index .= ''; $index .= ''; $index .= '
Month

'; $index .= ''; $index .= '
Year

'; $fp = fopen($rrdImgDir."index_".$n.".html","w"); fwrite ($fp,$index); fclose ($fp); } ?>