122 lines
3.5 KiB
Plaintext
122 lines
3.5 KiB
Plaintext
<code PHP>
|
|
<?PHP
|
|
|
|
|
|
$priceArea = array(
|
|
'dk' => 'DK_NORDPOOL_SPOT_DK1',
|
|
'fr' => 'FR_EPEX_SPOT_FR'
|
|
);
|
|
|
|
|
|
function getMethod($postData) {
|
|
// Le token suivant n'est pas valide. Il faut le modifier avec le votre, obtenu dans l'application Barry Eenrgy
|
|
$authToken = 'Bx6Da6v0h34MM7OhAjCaN9zak+IZLNe9tUlCebw7+LiP8+5SH6BcdNrOY85s9q7Sdfrmc/yyjWrJROlJ9vhlRCYY310TsHcGNodMzr3cGfZOwVYNPYWxGxcZHO94p6W98SJC/TdIYhsE+tRnvMMKHktTdkRjmMolHAtWpYyFzDw=';
|
|
$url = "https://jsonrpc.barry.energy/json-rpc";
|
|
|
|
echo "<pre>";
|
|
echo '<p>La méthode appelée : </p>';
|
|
print_r(json_encode($postData));
|
|
echo "</pre></br>";
|
|
|
|
|
|
// Create the context for the request
|
|
$context = stream_context_create(array(
|
|
'http' => array(
|
|
'method' => 'POST',
|
|
'header' => "Authorization: Bearer {$authToken}\r\n".
|
|
"Content-Type: application/json\r\n",
|
|
'content' => json_encode($postData)
|
|
)
|
|
));
|
|
|
|
// Send the request
|
|
$response = file_get_contents($url, FALSE, $context);
|
|
|
|
// Check for errors
|
|
if($response === FALSE){
|
|
die('Error');
|
|
}
|
|
return $response;
|
|
}
|
|
|
|
|
|
function translateDate($strDate) {
|
|
$nomJourSemaineEN = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
|
|
$nomJourSemaineFR = array("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche");
|
|
$nomMoisEN = array("January","February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
|
|
$nomMoisFR = array("Janvier","Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre");
|
|
$strDate = str_ireplace($nomMoisEN, $nomMoisFR, $strDate);
|
|
$strDate = str_ireplace($nomJourSemaineEN, $nomJourSemaineFR, $strDate);
|
|
return $strDate;
|
|
}
|
|
|
|
|
|
setlocale(LC_ALL,'fr');
|
|
|
|
//$dateJour=date('d F Y', strtotime('31-12-2018'));
|
|
$dateJour=date('d F Y');
|
|
$dateJourDemain=date('d F Y', strtotime('+1 day', strtotime($dateJour)));
|
|
|
|
echo "<h1>Métriques de Barry Energy</h1>";
|
|
echo "<p>Rapport établi le ".translateDate(date('l d F Y'))." à ".date('H:i:s')."</p>";
|
|
|
|
|
|
echo "<h2>Etat de l'abonnement</h2>";
|
|
|
|
// The data to send to the API getMeteringPoints
|
|
$postData = array('method' => 'co.getbarry.api.v1.OpenApiController.getMeteringPoints'
|
|
, 'id' => 0
|
|
, 'jsonrpc' => '2.0'
|
|
, 'params' => array()
|
|
);
|
|
|
|
$response = getMethod($postData);
|
|
// Decode the response
|
|
$responseData = json_decode($response, TRUE);
|
|
|
|
echo "<pre>";
|
|
echo '<p>La réponse : </p>';
|
|
print_r($responseData);
|
|
echo "</pre>";
|
|
|
|
|
|
echo "<h2>Consommation du $dateJour </h2>";
|
|
|
|
// The data to send to the API getAggregatedConsumption
|
|
$postData = array('method' => 'co.getbarry.api.v1.OpenApiController.getAggregatedConsumption'
|
|
, 'id' => 0
|
|
, 'jsonrpc' => '2.0'
|
|
, 'params' => array(date(DATE_ATOM, strtotime($dateJour)), date(DATE_ATOM, strtotime($dateJourDemain)))
|
|
);
|
|
|
|
$response = getMethod($postData);
|
|
// Decode the response
|
|
$responseData = json_decode($response, TRUE);
|
|
|
|
echo "<pre>";
|
|
echo '<p>La réponse : </p>';
|
|
print_r($responseData);
|
|
echo "</pre>";
|
|
|
|
|
|
|
|
echo "<h2>Prix du $dateJour </h2>";
|
|
|
|
// The data to send to the API getPrice
|
|
$postData = array('method' => 'co.getbarry.api.v1.OpenApiController.getPrice'
|
|
, 'id' => 0
|
|
, 'jsonrpc' => '2.0'
|
|
, 'params' => array($priceArea['fr'], date(DATE_ATOM, strtotime($dateJour)), date(DATE_ATOM, strtotime($dateJourDemain)) )
|
|
|
|
);
|
|
|
|
$response = getMethod($postData);
|
|
// Decode the response
|
|
$responseData = json_decode($response, TRUE);
|
|
|
|
echo "<pre>";
|
|
echo '<p>La réponse : </p>';
|
|
print_r($responseData);
|
|
echo "</pre>";
|
|
|
|
</code> |