5 exec("/usr/bin/rrdtool flushcached --daemon ".RRDSOCK." ".RRDFILE);
7 $fd = fopen(COUNTERFILE, 'r');
8 $mtime = fstat($fd)['mtime'];
9 $counter = (double)fread($fd, 128) * 1000;
12 #echo('counter='.$counter.'<br>');
17 'DEF:watts='.RRDFILE.':watts:AVERAGE',
18 'VDEF:avg=watts,AVERAGE',
19 #'VDEF:last=watts,LAST',
23 /*header("Content-Type: text/plain");
24 foreach ($params as $param) echo(escapeshellarg($param)." ");
26 $info=rrd_graph( '-', $params);
28 $watts_since_counter = (double)$info['calcpr'][0];
29 #$watts_last = (double)$info['calcpr'][1];
30 #echo('watts_since_counter='.$watts_since_counter.'<br>');
31 #echo('hours_since_counter='.((time() - $mtime) / 3600.).'<br>');
32 $wh_since_counter = $watts_since_counter * (time() - $mtime) / 3600.;
33 #echo('wh_since_counter='.$wh_since_counter.'<br>');
34 $newcounter = $counter + $wh_since_counter;
35 #echo('newcounter='.$newcounter.' kWh<br>');
37 $info=rrd_lastupdate(RRDFILE);
40 'last_update' => 'unknown',
45 'last_update' => $info['last_update'],
46 'watts' => (double)$info['data'][0]
50 #$result['watts'] = $watts_last;
51 $result['counter'] = $newcounter / 1000.;
53 header("Content-Type: text/json");
54 echo(json_encode($result));