Documentation
[ampy.git] / html / ampy.php
1 <?php
2 /*
3  * This file is not used!
4  */
5 $RRDFILE='/home/nirgal/ampy/power.rrd';
6 $COUNTERFILE='/home/nirgal/ampy/counter';
7
8 function get_counter() {
9         $fd = fopen($COUNTERFILE, 'r');
10         $mtime = fstat($fd)['mtime'];
11         $counter = (double)fread($fd, 128) * 1000;
12         fclose($fd);
13         #echo($mtime.'<br>');
14         #echo('counter='.$counter.'<br>');
15         
16         $info=rrd_graph( '-', ['-s', $mtime, 'DEF:watts='.$RRDFILE.':watts:AVERAGE', 'VDEF:avg=watts,AVERAGE', 'PRINT:avg:%lf']);
17         #print_r($info);
18         $watts_since_counter = (double)$info['calcpr'][0];
19         #echo('watts_since_counter='.$watts_since_counter.'<br>');
20         #echo('hours_since_counter='.((time() - $mtime) / 3600.).'<br>');
21         $wh_since_counter = $watts_since_counter * (time() - $mtime) / 3600.;
22         #echo('wh_since_counter='.$wh_since_counter.'<br>');
23         $counter += $wh_since_counter;
24         #echo('newcounter='.($counter/1000).' kWh<br>');
25
26         return $counter/1000.;
27 }
28 ?>