cdd300dacc213757eda183cfe368e05871ac512e
[ampy.git] / html / currentjson.php
1 <?php
2
3 require_once("config.php");
4 require_once("ampy.inc.php");
5
6 ampy_flush_rrd_daemon();
7
8 $info=rrd_lastupdate(RRDFILE);
9 if ($info === FALSE)
10         $result=[
11                 'last_update' => 'unknown',
12                 'watts' => 'unknown',
13                 'error' => rrd_error(),
14         ];
15 else
16         $result=[
17                 'last_update' => $info['last_update'],
18                 'watts' => (double)$info['data'][0]
19         ];
20
21 $result['counter'] = ampy_get_counter();
22
23 header("Content-Type: text/json");
24 echo(json_encode($result));
25 ?>