3 * Experimental version that return chunked http response.
5 * Pulling the values is no longer needed as the one request will output
6 * the updates every second.
8 require_once('config.php');
9 require_once("ampy.inc.php");
11 $speed=@(int)$_GET['speed'];
16 header("Content-Type: text/json");
17 header("Transfer-Encoding: chunked");
21 // Send chunk to browser
22 function send_chunk($chunk)
24 // The chunk must fill the output buffer or php won't send it
25 $chunk = str_pad($chunk, 4096);
27 printf("%x\r\n%s\r\n", strlen($chunk), $chunk);
32 ampy_flush_rrd_daemon();
34 $info=rrd_lastupdate(RRDFILE);
37 'last_update' => 'unknown',
39 'error' => rrd_error(),
43 'last_update' => $info['last_update'],
44 'watts' => (float)$info['data'][0],
46 $result['counter'] = ampy_get_counter();
47 send_chunk(json_encode($result));