comme je n'arrivais pas à faire marcher le code initial de ce post, je me suis créé un scénario qui interroge toutes les minutes l'envoy metered (ip/production.json) puis rempli un virtuel avec les données.
les données peuvent etre vu à l'adresse
http://ipmetered/production.json. A noter que firefox met en forme le json ce qui le rend bien lisible contrairement à explorer en chrome, en tout cas chez moi..
try {
// Get the contents of the JSON file
$strJsonFileContents = file_get_contents($url);
// Convert to array
$array = json_decode($strJsonFileContents, true);
$taille = sizeof($array);
if ($taille==3) {
//print_r($array[production][0][wNow]);
$interne_production_wnow=$array[production][0][wNow];
$sonde_production_wnow=round($array[production][1][wNow]);
$sonde_production_whtoday=round($array[production][1][whToday]);
//$sonde_production_vahtoday=round($array[production][1][vahToday]);
$sonde_oonso_whnow=round($array[consumption][0][wNow]);
$sonde_oonso_wtoday=round($array[consumption][0][whToday]);
$sonde_netconso_wnow=round($array[consumption][1][wNow]);
$sonde_netconso_whtoday=round($array[consumption][1][whToday]);
$cmd=cmd::byId(1193);
$cmd->event($interne_production_wnow);
$cmd=cmd::byId(1194);
$cmd->event($sonde_production_wnow);
$cmd=cmd::byId(1195);
$cmd->event($sonde_production_whtoday);
$cmd=cmd::byId(1196);
$cmd->event($sonde_oonso_whnow);
$cmd=cmd::byId(1197);
$cmd->event($sonde_oonso_wtoday);
$cmd=cmd::byId(1198);
$cmd->event($sonde_netconso_wnow);
}
}
//catch exception
catch(Exception $e) {
$scenario->setLog('Exception - ' .$e->getMessage());
}