Initial commit
This commit is contained in:
parent
942e195b0a
commit
e2cb18044f
46
get_smartme.php
Normal file
46
get_smartme.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
$smartmeUserName = "MY_SMARTME_USERNAME";
|
||||||
|
$smartmePassword = "MY_SMARTME_PASSWORD";
|
||||||
|
$smartmeQuery = "https://api.smart-me.com/api/Devices/";
|
||||||
|
|
||||||
|
// Create a stream
|
||||||
|
$opts = array(
|
||||||
|
'http'=>array(
|
||||||
|
'method'=>"GET",
|
||||||
|
'header'=>"Accept-language: en\r\n" .
|
||||||
|
"Authorization: Basic " . base64_encode("$smartmeUserName:$smartmePassword")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$context = stream_context_create($opts);
|
||||||
|
|
||||||
|
// Open the file using the HTTP headers set above
|
||||||
|
$smartme_output = file_get_contents($smartmeQuery, false, $context);
|
||||||
|
$response = json_decode($smartme_output, true);
|
||||||
|
|
||||||
|
$powerstate = $response[0]['SwitchOn'];
|
||||||
|
echo "Last updated: " . date('Y-m-d H:i:s', strtotime($response[0]['ValueDate'])) . "<br><br>";
|
||||||
|
|
||||||
|
echo "Name: " . $response[0]['Name'] . "<br>";
|
||||||
|
echo "Zählerstand komplett: " . $response[0]['CounterReading'] . " " . $response[0]['CounterReadingUnit'] . "<br><br>";
|
||||||
|
|
||||||
|
//echo "SwitchOn: " . $response[0]['SwitchOn'] . "<br>";
|
||||||
|
|
||||||
|
echo "<h4 <!--style='margin-bottom: 10px;'-- >Aktuelle Daten</h4>";
|
||||||
|
echo "Leistung: " . $response[0]['ActivePower'] . " " . $response[0]['ActivePowerUnit'] . "<br>";
|
||||||
|
echo "Spannung: " . $response[0]['Voltage'] . " V <br>";
|
||||||
|
echo "Strom: " . $response[0]['Current'] . " A <br>";
|
||||||
|
echo "Leistungsfaktor: " . $response[0]['PowerFactor'] . "<br>";
|
||||||
|
//echo "Active Power Unit: " . $response[0]['ActivePowerUnit'] . "<br>";
|
||||||
|
//echo "Counter Reading Unit: " . $response[0]['CounterReadingUnit'] . "<br>";
|
||||||
|
//echo "Counter Reading Import: " . $response[0]['CounterReadingImport'] . "<br>";
|
||||||
|
echo "Temperatur: " . $response[0]['Temperature'] . " °C<br>";
|
||||||
|
|
||||||
|
echo "<hr>";
|
||||||
|
|
||||||
|
if ($powerstate == "1"){
|
||||||
|
echo "<div style='background: green; height: 60%; color: white;'><div style='font-size: xx-large;position: relative; float: left; top: 50%; left: 50%; transform: translate(-50%, -50%);'>Power ON</div></div>";
|
||||||
|
} else {
|
||||||
|
echo "<div style='background: red; height: 60%; color: white;'><div style='font-size: xx-large;position: relative; float: left; top: 50%; left: 50%; transform: translate(-50%, -50%);'>Power OFF</div></div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
//var_dump($response[0]);?>
|
38
index.php
Normal file
38
index.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>smart-me metrics by m.reber</title>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||||
|
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Power stats</h1>
|
||||||
|
|
||||||
|
<div id="printPostResult"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function sendRequest(){
|
||||||
|
$.ajax({
|
||||||
|
url: "get_smartme.php",
|
||||||
|
success:
|
||||||
|
// Perform operation on the return value
|
||||||
|
function(data){
|
||||||
|
$('#printPostResult').html(data); //insert text of get_smartme.php into the div
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
// Schedule some stuff when the current operation is complete
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// The ready-function is automaticly executed, when the site is fully loaded
|
||||||
|
$(document).ready(function(){
|
||||||
|
|
||||||
|
sendRequest(); // Execute the Function once per page load (To load the content from begining)
|
||||||
|
setInterval(sendRequest,6000); //Execute the Function after every 6 seconds.
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user