Clean up duplicate php code to inc file
[ampy.git] / html / currentjson.php
index f3c8f315871e464a9106ec669c79d0fa14998d26..cdd300dacc213757eda183cfe368e05871ac512e 100644 (file)
@@ -1,17 +1,25 @@
 <?php
-$RRDFILE="/home/nirgal/ampy/power.rrd";
 
-$info=rrd_lastupdate($RRDFILE);
+require_once("config.php");
+require_once("ampy.inc.php");
+
+ampy_flush_rrd_daemon();
+
+$info=rrd_lastupdate(RRDFILE);
 if ($info === FALSE)
        $result=[
                'last_update' => 'unknown',
-               'watts' => 'unknown'
+               'watts' => 'unknown',
+               'error' => rrd_error(),
        ];
 else
        $result=[
                'last_update' => $info['last_update'],
-               'watts' => $info['data'][0]
+               'watts' => (double)$info['data'][0]
        ];
+
+$result['counter'] = ampy_get_counter();
+
 header("Content-Type: text/json");
 echo(json_encode($result));
 ?>