* Experimental version that return chunked http response.
*
* Pulling the values is no longer needed as the one request will output
- * the updates every 10 seconds.
+ * the updates every second.
*/
require_once('config.php');
+require_once("ampy.inc.php");
+
+$speed=@(int)$_GET['speed'];
+if ($speed <= 0)
+ $speed=1; // seconds
+
header("Content-Type: text/json");
header("Transfer-Encoding: chunked");
function send_chunk($chunk)
{
// The chunk must fill the output buffer or php won't send it
- $chunk = str_pad($chunk, 4096);
+ //$chunk = str_pad($chunk, 4096);
printf("%x\r\n%s\r\n", strlen($chunk), $chunk);
flush();
+ ob_flush();
}
while (True) {
+ ampy_flush_rrd_daemon();
+
$info=rrd_lastupdate(RRDFILE);
if ($info === FALSE)
$result=[
else
$result=[
'last_update' => $info['last_update'],
- 'watts' => $info['data'][0]
+ 'watts' => (float)$info['data'][0],
];
+ $result['counter'] = ampy_get_counter();
send_chunk(json_encode($result));
- sleep(10);
+ sleep($speed);
}
?>