Zeilenenden vereinheitlichen: LF ueberall ausser im Fremdcode
Bisher entschied jede Arbeitsstation fuer sich, welche Zeilenenden ein Commit bekommt: Git fuer Windows setzt core.autocrlf=input in seiner System-Konfiguration, die NAS setzt nichts. Weil der Bestand ausserdem in sich gemischt war - 34 PHP-Dateien mit LF, 30 mit CRLF -, gab es gar kein richtiges Zeilenende, an das ein Werkzeug sich haette halten koennen. Jede Ergaenzung mit LF in einer CRLF-Datei ergab eine gemischte Datei; helper.php und js/solar/homeMQTT.js waren bereits so entstanden. .gitattributes macht die Zeilenenden zur Eigenschaft des Repositorys. LF, weil dieses Verzeichnis der Web-Ordner der NAS ist und von Linux ausgeliefert wird - und weil Git fuer Windows mit "input" ohnehin schon dorthin zeigt. restricted/WebAuthn bleibt ausgenommen und damit byteweise so, wie die Bibliothek geliefert wurde; darunter liegen 292 Zertifikate. Von den 47 geaenderten Dateien wurde nachgerechnet keine einzige im Inhalt angefasst - der Vergleich HEAD-ohne-CR gegen Index ist ueberall gleich. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+161
-161
@@ -1,162 +1,162 @@
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
if(!isset($_GET["TO"])){
|
||||
$_GET["TO"] = 12;
|
||||
}
|
||||
$_GET["TO"] = intval($_GET["TO"]);
|
||||
if(!isset($_GET["FROM"])){
|
||||
$_GET["FROM"] = -24;
|
||||
}
|
||||
$_GET["FROM"] = intval($_GET["FROM"]);
|
||||
//-totalConsumption-PL1_EV*1000-PL2_EV*1000-PL3_EV*1000-PL1_EVog*1000-PL2_EVog*1000-PL3_EVog*1000+PL1_OG+PL2_OG+PL3_OG-heaterPwr AS 'UG',
|
||||
$consQuery = "SELECT
|
||||
UNIX_TIMESTAMP(EnergyFlow.datetime) AS time,
|
||||
pvP AS 'Solarleistung',
|
||||
soc AS Ladestand,
|
||||
-totalConsumption-PL1_EV*1000-PL2_EV*1000-PL3_EV*1000-PL1_EVog*1000-PL2_EVog*1000-PL3_EVog*1000+PL1_OG+PL2_OG+PL3_OG-heaterPwr-PL1_UG-PL2_UG-PL3_UG-PL1_EG-PL2_EG-PL3_EG AS 'Gemein',
|
||||
(PL1_UG+PL2_UG+PL3_UG) AS 'UG',
|
||||
(PL1_EG+PL2_EG+PL3_EG) AS 'EG',
|
||||
-(PL1_OG+PL2_OG+PL3_OG) AS 'OG',
|
||||
(PL1_EV+PL2_EV+PL3_EV)*1000 AS 'Auto UG',
|
||||
(PL1_EVog+PL2_EVog+PL3_EVog)*1000 AS 'Auto OG',
|
||||
heaterPwr AS 'Heizstab',
|
||||
IF(battP<0, -battP, 0) AS Batterieladung,
|
||||
gridPfeed AS Einspeisung
|
||||
FROM solarLog.EnergyFlow
|
||||
WHERE EnergyFlow.datetime BETWEEN DATE_ADD(NOW(),INTERVAL ".($_GET["FROM"])." HOUR) and DATE_ADD(NOW(),INTERVAL ".$_GET["TO"]." HOUR)
|
||||
ORDER BY EnergyFlow.datetime";
|
||||
$simQuery = "SELECT
|
||||
UNIX_TIMESTAMP(simPower.period_end) AS time,
|
||||
power*1000 AS 'Vorhersage'
|
||||
FROM solarLog.simPower
|
||||
WHERE simPower.period_end BETWEEN DATE_ADD(NOW(),INTERVAL ".($_GET["FROM"])." HOUR) and DATE_ADD(NOW(),INTERVAL ".$_GET["TO"]." HOUR)
|
||||
ORDER BY simPower.period_end";
|
||||
$linecolors["Solarleistung"] = "#FFFF00";
|
||||
$linecolors["Gemein"] = "#FF9900";
|
||||
$linecolors["UG"] = "#FF8800";
|
||||
$linecolors["EG"] = "#FF6600";
|
||||
$linecolors["OG"] = "#FF4400";
|
||||
$linecolors["Auto UG"] = "#00aaFF";
|
||||
$linecolors["Auto OG"] = "#0044FF";
|
||||
$linecolors["Heizstab"] = "#FF0000";
|
||||
$linecolors["Batterieladung"] = "#00aa00";
|
||||
$linecolors["Einspeisung"] = "#b0b0b0";
|
||||
$linecolors["Ladestand"] = "#00aa00";
|
||||
$linecolors["Vorhersage"] = "#2222FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$result = mysqli_query($mysql, $consQuery);
|
||||
$simRes = mysqli_query($mysql,$simQuery);
|
||||
if(!$result){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
$obj = (object)[]; // Cast empty array to object
|
||||
$obj->labels = [];
|
||||
$obj->datasets = [];
|
||||
$i = 0;
|
||||
$filled = 0;
|
||||
if ($simRes->num_rows > 1) {
|
||||
$dataset = (object)[];
|
||||
$row1 = $simRes->fetch_assoc();
|
||||
$dataset->borderColor = $linecolors["Vorhersage"];
|
||||
$dataset->backgroundColor = $linecolors["Vorhersage"]."55";
|
||||
$dataset->borderWidth=1.5;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->stack = "sim";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
$dataset->label = "Vorhersage";
|
||||
/*$pt = (object)[];
|
||||
$pt->x = $row1["time"]*1000;
|
||||
$pt->y = $row1["Vorhersage"];
|
||||
$dataset->data[] = clone $pt;
|
||||
while ($row1 = $simRes->fetch_assoc()) {
|
||||
$pt = (object)[];
|
||||
$pt->x = $row1["time"]*1000 + 30*60*1000;
|
||||
$pt->y = $row1["Vorhersage"];
|
||||
$dataset->data[] = clone $pt;
|
||||
}*/
|
||||
$obj->datasets[] = clone $dataset;
|
||||
$rownext = $simRes->fetch_assoc();
|
||||
$nextSimTimestamp = $rownext["time"]*1000 + 30*60*1000;
|
||||
}
|
||||
if ($result->num_rows > 1) {
|
||||
$ii = 1;
|
||||
$row = $result->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."55";
|
||||
$dataset->borderWidth=1;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
if ($name == "Solarleistung") {
|
||||
$dataset->stack = "SolarPwr";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
} else if ($name == "Ladestand") {
|
||||
$dataset->stack = "Charge";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y1';
|
||||
} else {
|
||||
$dataset->stack = "Consumers";
|
||||
if ($filled == 0) {
|
||||
$filled = 1;
|
||||
$dataset->fill = "origin";
|
||||
} else {
|
||||
$dataset->fill = "-1";
|
||||
}
|
||||
$dataset->yAxisID = 'y';
|
||||
}
|
||||
$dataset->label = $name;
|
||||
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
$ii++;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$ii = 1;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
} else {
|
||||
if(($value * 1000) < $nextSimTimestamp){
|
||||
$obj->datasets[0]->data[] = $row1["Vorhersage"];
|
||||
}else{
|
||||
$row1 = $rownext;
|
||||
$rownext = $simRes->fetch_assoc();
|
||||
$nextSimTimestamp = $rownext["time"]*1000 + 30*60*1000;
|
||||
$obj->datasets[0]->data[] = $row1["Vorhersage"];
|
||||
}
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$obj->labels[] = $nextSimTimestamp; //Draw future forecast
|
||||
$obj->datasets[0]->data[] = $rownext["Vorhersage"];
|
||||
while($rownext = $simRes->fetch_assoc()){
|
||||
$obj->labels[] = $rownext["time"]*1000 + 30*60*1000;
|
||||
$obj->datasets[0]->data[] = $rownext["Vorhersage"];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
if(!isset($_GET["TO"])){
|
||||
$_GET["TO"] = 12;
|
||||
}
|
||||
$_GET["TO"] = intval($_GET["TO"]);
|
||||
if(!isset($_GET["FROM"])){
|
||||
$_GET["FROM"] = -24;
|
||||
}
|
||||
$_GET["FROM"] = intval($_GET["FROM"]);
|
||||
//-totalConsumption-PL1_EV*1000-PL2_EV*1000-PL3_EV*1000-PL1_EVog*1000-PL2_EVog*1000-PL3_EVog*1000+PL1_OG+PL2_OG+PL3_OG-heaterPwr AS 'UG',
|
||||
$consQuery = "SELECT
|
||||
UNIX_TIMESTAMP(EnergyFlow.datetime) AS time,
|
||||
pvP AS 'Solarleistung',
|
||||
soc AS Ladestand,
|
||||
-totalConsumption-PL1_EV*1000-PL2_EV*1000-PL3_EV*1000-PL1_EVog*1000-PL2_EVog*1000-PL3_EVog*1000+PL1_OG+PL2_OG+PL3_OG-heaterPwr-PL1_UG-PL2_UG-PL3_UG-PL1_EG-PL2_EG-PL3_EG AS 'Gemein',
|
||||
(PL1_UG+PL2_UG+PL3_UG) AS 'UG',
|
||||
(PL1_EG+PL2_EG+PL3_EG) AS 'EG',
|
||||
-(PL1_OG+PL2_OG+PL3_OG) AS 'OG',
|
||||
(PL1_EV+PL2_EV+PL3_EV)*1000 AS 'Auto UG',
|
||||
(PL1_EVog+PL2_EVog+PL3_EVog)*1000 AS 'Auto OG',
|
||||
heaterPwr AS 'Heizstab',
|
||||
IF(battP<0, -battP, 0) AS Batterieladung,
|
||||
gridPfeed AS Einspeisung
|
||||
FROM solarLog.EnergyFlow
|
||||
WHERE EnergyFlow.datetime BETWEEN DATE_ADD(NOW(),INTERVAL ".($_GET["FROM"])." HOUR) and DATE_ADD(NOW(),INTERVAL ".$_GET["TO"]." HOUR)
|
||||
ORDER BY EnergyFlow.datetime";
|
||||
$simQuery = "SELECT
|
||||
UNIX_TIMESTAMP(simPower.period_end) AS time,
|
||||
power*1000 AS 'Vorhersage'
|
||||
FROM solarLog.simPower
|
||||
WHERE simPower.period_end BETWEEN DATE_ADD(NOW(),INTERVAL ".($_GET["FROM"])." HOUR) and DATE_ADD(NOW(),INTERVAL ".$_GET["TO"]." HOUR)
|
||||
ORDER BY simPower.period_end";
|
||||
$linecolors["Solarleistung"] = "#FFFF00";
|
||||
$linecolors["Gemein"] = "#FF9900";
|
||||
$linecolors["UG"] = "#FF8800";
|
||||
$linecolors["EG"] = "#FF6600";
|
||||
$linecolors["OG"] = "#FF4400";
|
||||
$linecolors["Auto UG"] = "#00aaFF";
|
||||
$linecolors["Auto OG"] = "#0044FF";
|
||||
$linecolors["Heizstab"] = "#FF0000";
|
||||
$linecolors["Batterieladung"] = "#00aa00";
|
||||
$linecolors["Einspeisung"] = "#b0b0b0";
|
||||
$linecolors["Ladestand"] = "#00aa00";
|
||||
$linecolors["Vorhersage"] = "#2222FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$result = mysqli_query($mysql, $consQuery);
|
||||
$simRes = mysqli_query($mysql,$simQuery);
|
||||
if(!$result){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
$obj = (object)[]; // Cast empty array to object
|
||||
$obj->labels = [];
|
||||
$obj->datasets = [];
|
||||
$i = 0;
|
||||
$filled = 0;
|
||||
if ($simRes->num_rows > 1) {
|
||||
$dataset = (object)[];
|
||||
$row1 = $simRes->fetch_assoc();
|
||||
$dataset->borderColor = $linecolors["Vorhersage"];
|
||||
$dataset->backgroundColor = $linecolors["Vorhersage"]."55";
|
||||
$dataset->borderWidth=1.5;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->stack = "sim";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
$dataset->label = "Vorhersage";
|
||||
/*$pt = (object)[];
|
||||
$pt->x = $row1["time"]*1000;
|
||||
$pt->y = $row1["Vorhersage"];
|
||||
$dataset->data[] = clone $pt;
|
||||
while ($row1 = $simRes->fetch_assoc()) {
|
||||
$pt = (object)[];
|
||||
$pt->x = $row1["time"]*1000 + 30*60*1000;
|
||||
$pt->y = $row1["Vorhersage"];
|
||||
$dataset->data[] = clone $pt;
|
||||
}*/
|
||||
$obj->datasets[] = clone $dataset;
|
||||
$rownext = $simRes->fetch_assoc();
|
||||
$nextSimTimestamp = $rownext["time"]*1000 + 30*60*1000;
|
||||
}
|
||||
if ($result->num_rows > 1) {
|
||||
$ii = 1;
|
||||
$row = $result->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."55";
|
||||
$dataset->borderWidth=1;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
if ($name == "Solarleistung") {
|
||||
$dataset->stack = "SolarPwr";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
} else if ($name == "Ladestand") {
|
||||
$dataset->stack = "Charge";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y1';
|
||||
} else {
|
||||
$dataset->stack = "Consumers";
|
||||
if ($filled == 0) {
|
||||
$filled = 1;
|
||||
$dataset->fill = "origin";
|
||||
} else {
|
||||
$dataset->fill = "-1";
|
||||
}
|
||||
$dataset->yAxisID = 'y';
|
||||
}
|
||||
$dataset->label = $name;
|
||||
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
$ii++;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$ii = 1;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
} else {
|
||||
if(($value * 1000) < $nextSimTimestamp){
|
||||
$obj->datasets[0]->data[] = $row1["Vorhersage"];
|
||||
}else{
|
||||
$row1 = $rownext;
|
||||
$rownext = $simRes->fetch_assoc();
|
||||
$nextSimTimestamp = $rownext["time"]*1000 + 30*60*1000;
|
||||
$obj->datasets[0]->data[] = $row1["Vorhersage"];
|
||||
}
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$obj->labels[] = $nextSimTimestamp; //Draw future forecast
|
||||
$obj->datasets[0]->data[] = $rownext["Vorhersage"];
|
||||
while($rownext = $simRes->fetch_assoc()){
|
||||
$obj->labels[] = $rownext["time"]*1000 + 30*60*1000;
|
||||
$obj->datasets[0]->data[] = $rownext["Vorhersage"];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
?>
|
||||
+171
-171
@@ -1,171 +1,171 @@
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
|
||||
$consEstQuery = "SELECT
|
||||
UNIX_TIMESTAMP(DATE_ADD(datetime, INTERVAL 28 DAY)) AS 'time',
|
||||
SUM(-(totalConsumption + heaterPwr)/48) AS 'Vorraussichtl. Verbrauch'
|
||||
FROM EnergyFlow
|
||||
WHERE
|
||||
DATE(datetime) >= DATE(DATE_SUB(NOW(),INTERVAL 28 DAY)) And DATE(datetime) != DATE(NOW())
|
||||
GROUP BY WEEKDAY(datetime)
|
||||
ORDER BY datetime";
|
||||
|
||||
$prodEstQuery = "SELECT UNIX_TIMESTAMP(CONVERT_TZ(period_End,'GMT','Europe/Berlin')) AS 'time',
|
||||
SUM(power*500) AS 'Vorhersage'
|
||||
FROM simPower
|
||||
WHERE DATE(CONVERT_TZ(period_End,'GMT','Europe/Berlin')) >= DATE(DATE_SUB(NOW(),INTERVAL 7 DAY))
|
||||
GROUP BY DAY(CONVERT_TZ(period_End,'GMT','Europe/Berlin'))
|
||||
ORDER BY period_End;";
|
||||
|
||||
$prodRealQuery = "SELECT
|
||||
UNIX_TIMESTAMP(datetime) AS 'time',
|
||||
SUM(pvP/12) AS 'Tatsächliche Erzeugung',
|
||||
SUM(-totalConsumption/12) AS 'Tatsächlicher Verbrauch'
|
||||
FROM EnergyFlow
|
||||
WHERE
|
||||
DATE(datetime) >= DATE(DATE_SUB(NOW(),INTERVAL 7 DAY))
|
||||
GROUP BY DAY(datetime)
|
||||
ORDER BY datetime";
|
||||
|
||||
|
||||
$linecolors["Tatsächliche Erzeugung"] = "#cccc00";
|
||||
$linecolors["Tatsächlicher Verbrauch"] = "#EE9900";
|
||||
$linecolors["Vorraussichtl. Verbrauch"] = "#BB4400";
|
||||
$linecolors["Auto UG"] = "#00aaFF";
|
||||
$linecolors["Auto OG"] = "#0044FF";
|
||||
$linecolors["Heizstab"] = "#FF0000";
|
||||
$linecolors["Batterieladung"] = "#00aa00";
|
||||
$linecolors["Einspeisung"] = "#b0b0b0";
|
||||
$linecolors["Ladestand"] = "#00aa00";
|
||||
$linecolors["Vorhersage"] = "#4444FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$consEst = mysqli_query($mysql, $consEstQuery);
|
||||
$prodEst = mysqli_query($mysql,$prodEstQuery);
|
||||
$prodReal = mysqli_query($mysql,$prodRealQuery);
|
||||
if(!$consEst){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
if(!$prodEst){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
if(!$prodRealQuery){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
|
||||
$obj = (object)[]; // Cast empty array to object
|
||||
$obj->labels = [];
|
||||
$obj->datasets = [];
|
||||
$i = 0;
|
||||
$filled = 0;
|
||||
|
||||
if($consEst->num_rows > 1){
|
||||
$row = $consEst->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."66";
|
||||
$dataset->borderWidth=1;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->stack = $name;
|
||||
//$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
$dataset->label = $name;
|
||||
for($i=0;$i<7;$i++){
|
||||
$dataset->data[] = NULL;
|
||||
}
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
}
|
||||
}
|
||||
while ($row = $consEst->fetch_assoc()) {
|
||||
$ii = 0;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($prodEst->num_rows > 1) {
|
||||
$row = $prodEst->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."55";
|
||||
$dataset->borderWidth=1;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->stack = $name;
|
||||
//$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
$dataset->label = $name;
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
while ($row = $prodEst->fetch_assoc()) {
|
||||
$ii = 1;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($prodReal->num_rows > 1){
|
||||
$row = $prodReal->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."55";
|
||||
$dataset->borderWidth=1;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->stack = $name;
|
||||
//$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
$dataset->label = $name;
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
}
|
||||
}
|
||||
while ($row = $prodReal->fetch_assoc()) {
|
||||
$ii = 2;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
|
||||
$consEstQuery = "SELECT
|
||||
UNIX_TIMESTAMP(DATE_ADD(datetime, INTERVAL 28 DAY)) AS 'time',
|
||||
SUM(-(totalConsumption + heaterPwr)/48) AS 'Vorraussichtl. Verbrauch'
|
||||
FROM EnergyFlow
|
||||
WHERE
|
||||
DATE(datetime) >= DATE(DATE_SUB(NOW(),INTERVAL 28 DAY)) And DATE(datetime) != DATE(NOW())
|
||||
GROUP BY WEEKDAY(datetime)
|
||||
ORDER BY datetime";
|
||||
|
||||
$prodEstQuery = "SELECT UNIX_TIMESTAMP(CONVERT_TZ(period_End,'GMT','Europe/Berlin')) AS 'time',
|
||||
SUM(power*500) AS 'Vorhersage'
|
||||
FROM simPower
|
||||
WHERE DATE(CONVERT_TZ(period_End,'GMT','Europe/Berlin')) >= DATE(DATE_SUB(NOW(),INTERVAL 7 DAY))
|
||||
GROUP BY DAY(CONVERT_TZ(period_End,'GMT','Europe/Berlin'))
|
||||
ORDER BY period_End;";
|
||||
|
||||
$prodRealQuery = "SELECT
|
||||
UNIX_TIMESTAMP(datetime) AS 'time',
|
||||
SUM(pvP/12) AS 'Tatsächliche Erzeugung',
|
||||
SUM(-totalConsumption/12) AS 'Tatsächlicher Verbrauch'
|
||||
FROM EnergyFlow
|
||||
WHERE
|
||||
DATE(datetime) >= DATE(DATE_SUB(NOW(),INTERVAL 7 DAY))
|
||||
GROUP BY DAY(datetime)
|
||||
ORDER BY datetime";
|
||||
|
||||
|
||||
$linecolors["Tatsächliche Erzeugung"] = "#cccc00";
|
||||
$linecolors["Tatsächlicher Verbrauch"] = "#EE9900";
|
||||
$linecolors["Vorraussichtl. Verbrauch"] = "#BB4400";
|
||||
$linecolors["Auto UG"] = "#00aaFF";
|
||||
$linecolors["Auto OG"] = "#0044FF";
|
||||
$linecolors["Heizstab"] = "#FF0000";
|
||||
$linecolors["Batterieladung"] = "#00aa00";
|
||||
$linecolors["Einspeisung"] = "#b0b0b0";
|
||||
$linecolors["Ladestand"] = "#00aa00";
|
||||
$linecolors["Vorhersage"] = "#4444FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$consEst = mysqli_query($mysql, $consEstQuery);
|
||||
$prodEst = mysqli_query($mysql,$prodEstQuery);
|
||||
$prodReal = mysqli_query($mysql,$prodRealQuery);
|
||||
if(!$consEst){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
if(!$prodEst){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
if(!$prodRealQuery){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
|
||||
$obj = (object)[]; // Cast empty array to object
|
||||
$obj->labels = [];
|
||||
$obj->datasets = [];
|
||||
$i = 0;
|
||||
$filled = 0;
|
||||
|
||||
if($consEst->num_rows > 1){
|
||||
$row = $consEst->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."66";
|
||||
$dataset->borderWidth=1;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->stack = $name;
|
||||
//$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
$dataset->label = $name;
|
||||
for($i=0;$i<7;$i++){
|
||||
$dataset->data[] = NULL;
|
||||
}
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
}
|
||||
}
|
||||
while ($row = $consEst->fetch_assoc()) {
|
||||
$ii = 0;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($prodEst->num_rows > 1) {
|
||||
$row = $prodEst->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."55";
|
||||
$dataset->borderWidth=1;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->stack = $name;
|
||||
//$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
$dataset->label = $name;
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
while ($row = $prodEst->fetch_assoc()) {
|
||||
$ii = 1;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($prodReal->num_rows > 1){
|
||||
$row = $prodReal->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."55";
|
||||
$dataset->borderWidth=1;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->stack = $name;
|
||||
//$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
$dataset->label = $name;
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
}
|
||||
}
|
||||
while ($row = $prodReal->fetch_assoc()) {
|
||||
$ii = 2;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
|
||||
+105
-105
@@ -1,105 +1,105 @@
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
|
||||
$heatQuery = "SELECT
|
||||
UNIX_TIMESTAMP(Heater.datetime) AS time,
|
||||
PufferU AS 'Speicher unten',
|
||||
PufferM AS 'Speicher mitte',
|
||||
PufferO AS 'Speicher oben',
|
||||
|
||||
|
||||
thermeVLfb AS 'Therme Vorlauf Fußboden',
|
||||
thermeRL AS 'Therme Rücklauf',
|
||||
heaterVL AS 'Heizstab Vorlauf',
|
||||
heaterRL AS 'Heizstab Rücklauf',
|
||||
fbVL AS 'Fußboden Vorlauf',
|
||||
fbRL AS 'Fußboden Rücklauf'
|
||||
FROM Heater
|
||||
WHERE Heater.datetime BETWEEN DATE_SUB(NOW(),INTERVAL 24 HOUR) and NOW()
|
||||
ORDER BY Heater.datetime";
|
||||
|
||||
$waterQuery = "SELECT UNIX_TIMESTAMP(wasser.datetime) AS time, rate AS 'Wasserverbrauch'
|
||||
FROM solarLog.wasser
|
||||
WHERE wasser.datetime BETWEEN DATE_SUB(NOW(),INTERVAL 24 HOUR) and NOW()
|
||||
ORDER BY wasser.datetime";
|
||||
|
||||
$linecolors["Speicher oben"] = "#FF5500";
|
||||
$linecolors["Speicher mitte"] = "#FFaa00";
|
||||
$linecolors["Speicher unten"] = "#FFFF00";
|
||||
$linecolors["Therme Vorlauf Fußboden"] = "#bb0000";
|
||||
$linecolors["Therme Rücklauf"] = "#ee0000";
|
||||
$linecolors["Heizstab Vorlauf"] = "#9900bb";
|
||||
$linecolors["Heizstab Rücklauf"] = "#8800aa";
|
||||
$linecolors["Fußboden Vorlauf"] = "#00FF00";
|
||||
$linecolors["Fußboden Rücklauf"] = "#00aa00";
|
||||
$linecolors["Wasserverbrauch"] = "#2222FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$result = mysqli_query($mysql, $heatQuery);
|
||||
$simRes = mysqli_query($mysql,$waterQuery);
|
||||
if(!$result){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
$obj = (object)[]; // Cast empty array to object
|
||||
$obj->labels = [];
|
||||
$obj->datasets = [];
|
||||
$i = 0;
|
||||
$filled = 0;
|
||||
|
||||
if ($result->num_rows > 1) {
|
||||
$ii = 0;
|
||||
$row = $result->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."22";
|
||||
$dataset->borderWidth=2;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
if(strpos($name,"Speicher") === false) {
|
||||
$dataset->fill = "none";
|
||||
} else {
|
||||
// $dataset->stack = "Consumers";
|
||||
if ($filled == 0) {
|
||||
$filled = 1;
|
||||
$dataset->fill = "origin";
|
||||
} else {
|
||||
$dataset->fill = "-1";
|
||||
}
|
||||
$dataset->yAxisID = 'y';
|
||||
}
|
||||
$dataset->label = $name;
|
||||
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
$ii++;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$ii = 0;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
|
||||
$heatQuery = "SELECT
|
||||
UNIX_TIMESTAMP(Heater.datetime) AS time,
|
||||
PufferU AS 'Speicher unten',
|
||||
PufferM AS 'Speicher mitte',
|
||||
PufferO AS 'Speicher oben',
|
||||
|
||||
|
||||
thermeVLfb AS 'Therme Vorlauf Fußboden',
|
||||
thermeRL AS 'Therme Rücklauf',
|
||||
heaterVL AS 'Heizstab Vorlauf',
|
||||
heaterRL AS 'Heizstab Rücklauf',
|
||||
fbVL AS 'Fußboden Vorlauf',
|
||||
fbRL AS 'Fußboden Rücklauf'
|
||||
FROM Heater
|
||||
WHERE Heater.datetime BETWEEN DATE_SUB(NOW(),INTERVAL 24 HOUR) and NOW()
|
||||
ORDER BY Heater.datetime";
|
||||
|
||||
$waterQuery = "SELECT UNIX_TIMESTAMP(wasser.datetime) AS time, rate AS 'Wasserverbrauch'
|
||||
FROM solarLog.wasser
|
||||
WHERE wasser.datetime BETWEEN DATE_SUB(NOW(),INTERVAL 24 HOUR) and NOW()
|
||||
ORDER BY wasser.datetime";
|
||||
|
||||
$linecolors["Speicher oben"] = "#FF5500";
|
||||
$linecolors["Speicher mitte"] = "#FFaa00";
|
||||
$linecolors["Speicher unten"] = "#FFFF00";
|
||||
$linecolors["Therme Vorlauf Fußboden"] = "#bb0000";
|
||||
$linecolors["Therme Rücklauf"] = "#ee0000";
|
||||
$linecolors["Heizstab Vorlauf"] = "#9900bb";
|
||||
$linecolors["Heizstab Rücklauf"] = "#8800aa";
|
||||
$linecolors["Fußboden Vorlauf"] = "#00FF00";
|
||||
$linecolors["Fußboden Rücklauf"] = "#00aa00";
|
||||
$linecolors["Wasserverbrauch"] = "#2222FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$result = mysqli_query($mysql, $heatQuery);
|
||||
$simRes = mysqli_query($mysql,$waterQuery);
|
||||
if(!$result){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
$obj = (object)[]; // Cast empty array to object
|
||||
$obj->labels = [];
|
||||
$obj->datasets = [];
|
||||
$i = 0;
|
||||
$filled = 0;
|
||||
|
||||
if ($result->num_rows > 1) {
|
||||
$ii = 0;
|
||||
$row = $result->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."22";
|
||||
$dataset->borderWidth=2;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
if(strpos($name,"Speicher") === false) {
|
||||
$dataset->fill = "none";
|
||||
} else {
|
||||
// $dataset->stack = "Consumers";
|
||||
if ($filled == 0) {
|
||||
$filled = 1;
|
||||
$dataset->fill = "origin";
|
||||
} else {
|
||||
$dataset->fill = "-1";
|
||||
}
|
||||
$dataset->yAxisID = 'y';
|
||||
}
|
||||
$dataset->label = $name;
|
||||
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
$ii++;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$ii = 0;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
|
||||
+164
-164
@@ -1,165 +1,165 @@
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
if(!isset($_GET["TO"])){
|
||||
$_GET["TO"] = 12;
|
||||
}
|
||||
$_GET["TO"] = intval($_GET["TO"]);
|
||||
if(!isset($_GET["FROM"])){
|
||||
$_GET["FROM"] = -24;
|
||||
}
|
||||
$_GET["FROM"] = intval($_GET["FROM"]);
|
||||
$consQuery = "SELECT
|
||||
UNIX_TIMESTAMP(EnergyFlow.datetime) AS time,
|
||||
pvP AS Solarleistung,
|
||||
IF(-totalConsumption - IF(gridP>0, gridP, 0) - IF(battP>0, battP, 0) > 0, -totalConsumption - IF(gridP>0, gridP, 0) - IF(battP>0, battP, 0), 0) AS Direktverbrauch,
|
||||
IF(battP>0, battP, 0) AS Batteriebezug,
|
||||
gridPcons AS Netzbezug,
|
||||
-totalConsumption AS Verbrauch,".
|
||||
//IF(battP<0, -battP, 0) AS Batterieladung,
|
||||
"soc AS Ladestand
|
||||
FROM solarLog.EnergyFlow
|
||||
WHERE EnergyFlow.datetime BETWEEN DATE_ADD(NOW(),INTERVAL ".($_GET["FROM"])." HOUR) and DATE_ADD(NOW(),INTERVAL ".$_GET["TO"]." HOUR)
|
||||
ORDER BY EnergyFlow.datetime";
|
||||
|
||||
$simQuery = "SELECT
|
||||
UNIX_TIMESTAMP(simPower.period_end) AS time,
|
||||
power*1000 AS 'Vorhersage'
|
||||
FROM solarLog.simPower
|
||||
WHERE simPower.period_end BETWEEN DATE_ADD(NOW(),INTERVAL ".($_GET["FROM"])." HOUR) and DATE_ADD(NOW(),INTERVAL ".$_GET["TO"]." HOUR)
|
||||
ORDER BY simPower.period_end";
|
||||
$linecolors["Solarleistung"] = "#FFFF00";
|
||||
$linecolors["Direktverbrauch"] = "#FFcc00";
|
||||
$linecolors["Verbrauch"] = "#FFaa44";
|
||||
$linecolors["Auto UG"] = "#00aaFF";
|
||||
$linecolors["Auto OG"] = "#0044FF";
|
||||
$linecolors["Netzbezug"] = "#FF0000";
|
||||
$linecolors["Batteriebezug"] = "#00aa00";
|
||||
$linecolors["Batterieladung"] = "#0033aa";
|
||||
$linecolors["Einspeisung"] = "#b0b0b0";
|
||||
$linecolors["Ladestand"] = "#00aa00";
|
||||
$linecolors["Vorhersage"] = "#2222FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$result = mysqli_query($mysql, $consQuery);
|
||||
$simRes = mysqli_query($mysql,$simQuery);
|
||||
if(!$result){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
$obj = (object)[]; // Cast empty array to object
|
||||
$obj->labels = [];
|
||||
$obj->datasets = [];
|
||||
$i = 0;
|
||||
$filled = 0;
|
||||
if ($simRes->num_rows > 1) {
|
||||
$dataset = (object)[];
|
||||
$row1 = $simRes->fetch_assoc();
|
||||
$dataset->borderColor = $linecolors["Vorhersage"];
|
||||
$dataset->backgroundColor = $linecolors["Vorhersage"]."55";
|
||||
$dataset->borderWidth=1.5;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->stack = "sim";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
$dataset->label = "Vorhersage";
|
||||
/*$pt = (object)[];
|
||||
$pt->x = $row["time"]*1000;
|
||||
$pt->y = $row["Vorhersage"];
|
||||
$dataset->data[] = clone $pt;
|
||||
while ($row = $simRes->fetch_assoc()) {
|
||||
$pt = (object)[];
|
||||
$pt->x = $row["time"]*1000 + 30*60*1000;
|
||||
$pt->y = $row["Vorhersage"];
|
||||
$dataset->data[] = clone $pt;
|
||||
}*/
|
||||
$obj->datasets[] = clone $dataset;
|
||||
$rownext = $simRes->fetch_assoc();
|
||||
$nextSimTimestamp = $rownext["time"]*1000 + 30*60*1000;
|
||||
}
|
||||
if ($result->num_rows > 1) {
|
||||
$ii = 1;
|
||||
$row = $result->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."22";
|
||||
$dataset->borderWidth=1;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
if ($name == "Solarleistung") {
|
||||
$dataset->stack = "SolarPwr";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
}else if ($name == "Verbrauch") {
|
||||
$dataset->stack = "ConsPwr";
|
||||
$dataset->fill = "1";
|
||||
$dataset->yAxisID = 'y';
|
||||
}else if ($name == "Batterieladung") {
|
||||
$dataset->stack = "ConsPwr";
|
||||
$dataset->fill = "-1";
|
||||
$dataset->backgroundColor = $linecolors[$name]."77";
|
||||
$dataset->yAxisID = 'y';
|
||||
} else if ($name == "Ladestand") {
|
||||
$dataset->stack = "Charge";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y1';
|
||||
} else {
|
||||
$dataset->stack = "Consumers";
|
||||
if ($filled == 0) {
|
||||
$filled = 1;
|
||||
$dataset->fill = "origin";
|
||||
} else {
|
||||
$dataset->fill = "-1";
|
||||
}
|
||||
$dataset->yAxisID = 'y';
|
||||
}
|
||||
$dataset->label = $name;
|
||||
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
$ii++;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$ii = 1;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
} else {
|
||||
if(($value * 1000) < $nextSimTimestamp){
|
||||
$obj->datasets[0]->data[] = $row1["Vorhersage"];
|
||||
}else{
|
||||
$row1 = $rownext;
|
||||
$rownext = $simRes->fetch_assoc();
|
||||
$nextSimTimestamp = $rownext["time"]*1000 + 30*60*1000;
|
||||
$obj->datasets[0]->data[] = $row1["Vorhersage"];
|
||||
}
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$obj->labels[] = $nextSimTimestamp; //Draw future forecast
|
||||
$obj->datasets[0]->data[] = $rownext["Vorhersage"];
|
||||
while($rownext = $simRes->fetch_assoc()){
|
||||
$obj->labels[] = $rownext["time"]*1000 + 30*60*1000;
|
||||
$obj->datasets[0]->data[] = $rownext["Vorhersage"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
if(!isset($_GET["TO"])){
|
||||
$_GET["TO"] = 12;
|
||||
}
|
||||
$_GET["TO"] = intval($_GET["TO"]);
|
||||
if(!isset($_GET["FROM"])){
|
||||
$_GET["FROM"] = -24;
|
||||
}
|
||||
$_GET["FROM"] = intval($_GET["FROM"]);
|
||||
$consQuery = "SELECT
|
||||
UNIX_TIMESTAMP(EnergyFlow.datetime) AS time,
|
||||
pvP AS Solarleistung,
|
||||
IF(-totalConsumption - IF(gridP>0, gridP, 0) - IF(battP>0, battP, 0) > 0, -totalConsumption - IF(gridP>0, gridP, 0) - IF(battP>0, battP, 0), 0) AS Direktverbrauch,
|
||||
IF(battP>0, battP, 0) AS Batteriebezug,
|
||||
gridPcons AS Netzbezug,
|
||||
-totalConsumption AS Verbrauch,".
|
||||
//IF(battP<0, -battP, 0) AS Batterieladung,
|
||||
"soc AS Ladestand
|
||||
FROM solarLog.EnergyFlow
|
||||
WHERE EnergyFlow.datetime BETWEEN DATE_ADD(NOW(),INTERVAL ".($_GET["FROM"])." HOUR) and DATE_ADD(NOW(),INTERVAL ".$_GET["TO"]." HOUR)
|
||||
ORDER BY EnergyFlow.datetime";
|
||||
|
||||
$simQuery = "SELECT
|
||||
UNIX_TIMESTAMP(simPower.period_end) AS time,
|
||||
power*1000 AS 'Vorhersage'
|
||||
FROM solarLog.simPower
|
||||
WHERE simPower.period_end BETWEEN DATE_ADD(NOW(),INTERVAL ".($_GET["FROM"])." HOUR) and DATE_ADD(NOW(),INTERVAL ".$_GET["TO"]." HOUR)
|
||||
ORDER BY simPower.period_end";
|
||||
$linecolors["Solarleistung"] = "#FFFF00";
|
||||
$linecolors["Direktverbrauch"] = "#FFcc00";
|
||||
$linecolors["Verbrauch"] = "#FFaa44";
|
||||
$linecolors["Auto UG"] = "#00aaFF";
|
||||
$linecolors["Auto OG"] = "#0044FF";
|
||||
$linecolors["Netzbezug"] = "#FF0000";
|
||||
$linecolors["Batteriebezug"] = "#00aa00";
|
||||
$linecolors["Batterieladung"] = "#0033aa";
|
||||
$linecolors["Einspeisung"] = "#b0b0b0";
|
||||
$linecolors["Ladestand"] = "#00aa00";
|
||||
$linecolors["Vorhersage"] = "#2222FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$result = mysqli_query($mysql, $consQuery);
|
||||
$simRes = mysqli_query($mysql,$simQuery);
|
||||
if(!$result){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
$obj = (object)[]; // Cast empty array to object
|
||||
$obj->labels = [];
|
||||
$obj->datasets = [];
|
||||
$i = 0;
|
||||
$filled = 0;
|
||||
if ($simRes->num_rows > 1) {
|
||||
$dataset = (object)[];
|
||||
$row1 = $simRes->fetch_assoc();
|
||||
$dataset->borderColor = $linecolors["Vorhersage"];
|
||||
$dataset->backgroundColor = $linecolors["Vorhersage"]."55";
|
||||
$dataset->borderWidth=1.5;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->stack = "sim";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
$dataset->label = "Vorhersage";
|
||||
/*$pt = (object)[];
|
||||
$pt->x = $row["time"]*1000;
|
||||
$pt->y = $row["Vorhersage"];
|
||||
$dataset->data[] = clone $pt;
|
||||
while ($row = $simRes->fetch_assoc()) {
|
||||
$pt = (object)[];
|
||||
$pt->x = $row["time"]*1000 + 30*60*1000;
|
||||
$pt->y = $row["Vorhersage"];
|
||||
$dataset->data[] = clone $pt;
|
||||
}*/
|
||||
$obj->datasets[] = clone $dataset;
|
||||
$rownext = $simRes->fetch_assoc();
|
||||
$nextSimTimestamp = $rownext["time"]*1000 + 30*60*1000;
|
||||
}
|
||||
if ($result->num_rows > 1) {
|
||||
$ii = 1;
|
||||
$row = $result->fetch_assoc();
|
||||
foreach ($row as $name => $value) {
|
||||
$dataset = (object)[];
|
||||
if ($name != "time") {
|
||||
$dataset->borderColor = $linecolors[$name];
|
||||
$dataset->backgroundColor = $linecolors[$name]."22";
|
||||
$dataset->borderWidth=1;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
if ($name == "Solarleistung") {
|
||||
$dataset->stack = "SolarPwr";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y';
|
||||
}else if ($name == "Verbrauch") {
|
||||
$dataset->stack = "ConsPwr";
|
||||
$dataset->fill = "1";
|
||||
$dataset->yAxisID = 'y';
|
||||
}else if ($name == "Batterieladung") {
|
||||
$dataset->stack = "ConsPwr";
|
||||
$dataset->fill = "-1";
|
||||
$dataset->backgroundColor = $linecolors[$name]."77";
|
||||
$dataset->yAxisID = 'y';
|
||||
} else if ($name == "Ladestand") {
|
||||
$dataset->stack = "Charge";
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y1';
|
||||
} else {
|
||||
$dataset->stack = "Consumers";
|
||||
if ($filled == 0) {
|
||||
$filled = 1;
|
||||
$dataset->fill = "origin";
|
||||
} else {
|
||||
$dataset->fill = "-1";
|
||||
}
|
||||
$dataset->yAxisID = 'y';
|
||||
}
|
||||
$dataset->label = $name;
|
||||
|
||||
$dataset->data[] = $value;
|
||||
$obj->datasets[] = clone $dataset;
|
||||
$ii++;
|
||||
} else {
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$ii = 1;
|
||||
foreach ($row as $name => $value) {
|
||||
if ($name != "time") {
|
||||
$obj->datasets[$ii]->data[] = $value;
|
||||
$ii++;
|
||||
} else {
|
||||
if(($value * 1000) < $nextSimTimestamp){
|
||||
$obj->datasets[0]->data[] = $row1["Vorhersage"];
|
||||
}else{
|
||||
$row1 = $rownext;
|
||||
$rownext = $simRes->fetch_assoc();
|
||||
$nextSimTimestamp = $rownext["time"]*1000 + 30*60*1000;
|
||||
$obj->datasets[0]->data[] = $row1["Vorhersage"];
|
||||
}
|
||||
$obj->labels[] = $value * 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$obj->labels[] = $nextSimTimestamp; //Draw future forecast
|
||||
$obj->datasets[0]->data[] = $rownext["Vorhersage"];
|
||||
while($rownext = $simRes->fetch_assoc()){
|
||||
$obj->labels[] = $rownext["time"]*1000 + 30*60*1000;
|
||||
$obj->datasets[0]->data[] = $rownext["Vorhersage"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
?>
|
||||
+211
-211
@@ -1,211 +1,211 @@
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
require_once("../restricted/costs.php");
|
||||
if(!isset($_GET["year"])){
|
||||
$_GET["year"] = date("Y");
|
||||
}else{
|
||||
$_GET["year"] = intval($_GET["year"]);
|
||||
}
|
||||
if($_GET["year"] < 2018 || $_GET["year"] > date("Y")){
|
||||
exit;
|
||||
}
|
||||
if(isset($_GET["type"])){
|
||||
if(strtolower($_GET["type"]) =="lastyear"){
|
||||
$_GET["year"] = date("Y")-1;
|
||||
}elseif(strtolower($_GET["type"]) =="prelastyear"){
|
||||
$_GET["year"] = date("Y")-2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Jahresstatistik als eine Abfrage - jetzt auf stats_daily.
|
||||
*
|
||||
* Gerechnet wird nicht mehr ueber die Rohdaten aus EnergyFlow, sondern ueber
|
||||
* die Tageswerte. Zwei Gruende:
|
||||
*
|
||||
* 1. Die Rohdaten werden nach zwoelf Monaten ausgeduennt bzw. ins
|
||||
* Stundenarchiv verschoben (solarlog-rollup.sh). Eine Kachel, die auf
|
||||
* EnergyFlow rechnet, zeigt fuer alte Jahre danach zu wenig an.
|
||||
* 2. Ein Jahr sind 365 Zeilen statt rund 105.000.
|
||||
*
|
||||
* Die Tarife bleiben unveraendert: je Zeile ein Stichtag, das Ende holt
|
||||
* LEAD() beim naechsten. Weil ein Stichtag ein DATUM ist, kann ein Tag nie
|
||||
* zwei Tarife haben - die Verdichtung auf Tage verliert hier also nichts.
|
||||
*
|
||||
* Was in stats_daily vorberechnet sein MUSS, weil es eine Bedingung je
|
||||
* Messwert auswertet und sich aus Tagessummen nicht rekonstruieren laesst:
|
||||
*
|
||||
* eigenverbrauch_kwh pv - Einspeisung - Batterieladung
|
||||
* - Heizstab + Batterieentladung. Dazu addiert
|
||||
* wird pv_fehlbetrag_kwh: bei Ausfall einzelner
|
||||
* Wechselrichter fehlt deren Beitrag in pv, alle
|
||||
* Senken sind dagegen gemessen - die Differenz
|
||||
* faellt sonst zu klein oder negativ aus.
|
||||
* heizstab_solar_kwh Heizstab, anteilig nach autonomy
|
||||
* auto_*_solar_kwh Wallbox, anteilig nach autonomy - dem vom
|
||||
* Geraet in feiner Aufloesung gerechneten
|
||||
* Nicht-Netz-Anteil der Zufuhr
|
||||
*
|
||||
* Einheiten sind in stats_daily bereits bereinigt: PL*_EV und PL*_EVog
|
||||
* liefern Kilowatt, alle uebrigen Leistungsspalten Watt. In der alten
|
||||
* Abfrage stand das als /12 gegen /12000 nebeneinander.
|
||||
*
|
||||
* Die Solaranteile teilen jetzt durch NULLIF(...): ohne Ladung im Jahr kam
|
||||
* vorher 0/0 heraus.
|
||||
*
|
||||
* "Ersparnis Batterie" rechnet den Nutzen netto: was die entladene Energie
|
||||
* aus dem Netz gekostet haette, abzueglich der Verguetung, die fuer den zum
|
||||
* Laden verwendeten Strom entgangen ist. Brutto waere die Kachel zu
|
||||
* freundlich - der Speicher ist nicht umsonst zu fuellen.
|
||||
*
|
||||
* Achtung beim Lesen: "Verbrauchsersparnis" ist der GESAMTE Eigenverbrauch
|
||||
* zum Strompreis. "Ersparnis Batterie" und "Ersparnis Solarladung" sind
|
||||
* Teilmengen davon, nach Herkunft bzw. Verwendung herausgegriffen. Sie
|
||||
* duerfen nicht addiert werden.
|
||||
*
|
||||
* Der Grundpreis fehlt weiterhin bewusst - er haengt an den Tagen des
|
||||
* Jahres, nicht an einem Messwert, und kommt aus grundpreisImJahr() dazu.
|
||||
*/
|
||||
function statistikAbfrage($jahr)
|
||||
{
|
||||
return "WITH
|
||||
preis AS (SELECT active_date, cost, gain,
|
||||
LEAD(active_date) OVER (ORDER BY active_date) AS folgt FROM gridCosts),
|
||||
gas AS (SELECT active_date, cost, kwhPerLitre,
|
||||
LEAD(active_date) OVER (ORDER BY active_date) AS folgt FROM gasCosts),
|
||||
sprit AS (SELECT active_date, cost, lPer100km, kwhPer100km,
|
||||
LEAD(active_date) OVER (ORDER BY active_date) AS folgt FROM fuelCosts)
|
||||
SELECT
|
||||
SUM(d.netz_bezug_kwh) AS 'Stromverbrauch',
|
||||
SUM(d.netz_bezug_kwh * preis.cost) AS 'Stromkosten',
|
||||
SUM((d.eigenverbrauch_kwh + IFNULL(d.pv_fehlbetrag_kwh,0)) * preis.cost) AS 'Verbrauchsersparnis',
|
||||
SUM(d.netz_einsp_kwh * preis.gain) AS 'Einspeisevergütung',
|
||||
SUM(d.heizstab_solar_kwh * gas.cost / NULLIF(gas.kwhPerLitre,0)) AS 'Ersparnis Heizung',
|
||||
SUM(d.batt_entladen_kwh * preis.cost - d.batt_laden_kwh * preis.gain) AS 'Ersparnis Batterie',
|
||||
SUM(d.autarkie_avg * d.stunden_erfasst) / NULLIF(SUM(d.stunden_erfasst),0) AS 'Ø Autarkie',
|
||||
SUM(d.auto_eg_kwh) AS 'Autoladung ges. EG',
|
||||
SUM(d.auto_eg_solar_kwh) / NULLIF(SUM(d.auto_eg_kwh),0) * 100 AS 'Autoladung Solar EG',
|
||||
SUM(d.auto_eg_solar_kwh * preis.cost) AS 'Ersparnis Solarladung EG',
|
||||
SUM(d.auto_eg_kwh * sprit.lPer100km / NULLIF(sprit.kwhPer100km,0)) AS 'Benzin gespart EG',
|
||||
SUM(d.auto_eg_kwh * sprit.lPer100km / NULLIF(sprit.kwhPer100km,0) * sprit.cost) AS 'Ersparnis Benzin EG',
|
||||
SUM(d.auto_og_kwh) AS 'Autoladung ges. OG',
|
||||
SUM(d.auto_og_solar_kwh) / NULLIF(SUM(d.auto_og_kwh),0) * 100 AS 'Autoladung Solar OG',
|
||||
SUM(d.auto_og_solar_kwh * preis.cost) AS 'Ersparnis Solarladung OG',
|
||||
SUM(d.auto_og_kwh * sprit.lPer100km / NULLIF(sprit.kwhPer100km,0)) AS 'Benzin gespart OG',
|
||||
SUM(d.auto_og_kwh * sprit.lPer100km / NULLIF(sprit.kwhPer100km,0) * sprit.cost) AS 'Ersparnis Benzin OG'
|
||||
FROM stats_daily d
|
||||
JOIN preis ON d.tag >= preis.active_date AND (preis.folgt IS NULL OR d.tag < preis.folgt)
|
||||
LEFT JOIN gas ON d.tag >= gas.active_date AND (gas.folgt IS NULL OR d.tag < gas.folgt)
|
||||
LEFT JOIN sprit ON d.tag >= sprit.active_date AND (sprit.folgt IS NULL OR d.tag < sprit.folgt)
|
||||
WHERE YEAR(d.tag) = " . intval($jahr) . ";";
|
||||
}
|
||||
|
||||
$Query = statistikAbfrage($_GET["year"]);
|
||||
$PrevQuery = statistikAbfrage($_GET["year"] - 1);
|
||||
|
||||
// Reihenfolge wie in der Abfrage, mit "Verg.+Einsp. Strom" an Stelle 4.
|
||||
$units = Array("kWh","€","€","€","€","€","€","%",
|
||||
"kWh","%","€","L","€",
|
||||
"kWh","%","€","L","€");
|
||||
// Nur bei Verbrauch und Kosten ist weniger besser.
|
||||
$LessIsBetter = array_merge([true, true], array_fill(0, count($units) - 2, false));
|
||||
|
||||
function array_insert($array,$values,$offset) {
|
||||
return array_slice($array, 0, $offset, true) + $values + array_slice($array, $offset, NULL, true);
|
||||
}
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
|
||||
$html = "<div class='row row-cols-2 row-cols-md-4 g-2 row-info'>";
|
||||
$mysql = solarDb();
|
||||
$Res = mysqli_query($mysql,$Query);
|
||||
$ResPrev = mysqli_query($mysql,$PrevQuery);
|
||||
if(!$Res || !$ResPrev){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
if ($Res->num_rows > 0) {
|
||||
$i = 0;
|
||||
$row = $Res->fetch_assoc();
|
||||
$rowPrev = $ResPrev->fetch_assoc();
|
||||
// Der Grundpreis faellt unabhaengig vom Verbrauch an und laesst sich
|
||||
// deshalb nicht aus den Messwerten summieren.
|
||||
$row["Stromkosten"] += grundpreisImJahr($_GET["year"]);
|
||||
$rowPrev["Stromkosten"] += grundpreisImJahr($_GET["year"] - 1);
|
||||
//$row["Vergütung+Einsparung Strom"] = $row["Einspeisevergütung"]+$row["Verbrauchsersparnis"];
|
||||
$row = array_insert($row,["Verg.+Einsp. Strom" => $row["Einspeisevergütung"]+$row["Verbrauchsersparnis"]],4);
|
||||
$rowPrev = array_insert($rowPrev,["Verg.+Einsp. Strom" => $rowPrev["Einspeisevergütung"]+$rowPrev["Verbrauchsersparnis"]],4);
|
||||
$i = 0;
|
||||
foreach ($row as $name => $value) {
|
||||
if(str_starts_with($name,"Autoladung ges.")){
|
||||
$html .= "</div><hr class='mt-3 mb-3 border-light' />";
|
||||
$html .= "<div class='row row-cols-2 row-cols-md-4 g-2 row-info'>";
|
||||
}
|
||||
/*$html .= "<div class='col-12 col-sm-4 col-md-2 col-xl-1'>
|
||||
<div class='info-box'>
|
||||
<div class='info-box-content'>
|
||||
<span class='info-box-text'>".$name."</span>
|
||||
<span class='info-box-number'>".
|
||||
number_format(floatval($value),2,",",".")
|
||||
."<small>".$units[$i++]."</small>
|
||||
</span>
|
||||
</div>
|
||||
<!-- /.info-box-content -->
|
||||
</div>
|
||||
</div>";*/
|
||||
$html .= "<div class='col'>
|
||||
<div class='card stats border-0'>
|
||||
<div class='card-body bg-dark bg-gradient rounded-top pb-1 pt-1'>
|
||||
".$name."
|
||||
</div>
|
||||
<div class='card-footer text-center'>";
|
||||
if($_GET["year"] != date("Y")){
|
||||
if($LessIsBetter[$i]){
|
||||
if($value == 0)
|
||||
$dev=100;
|
||||
else
|
||||
$dev = $rowPrev[$name]/$value;
|
||||
//$first = round($rowPrev[$name]*10/$rowPrev[$name]); //allow for 10% deviation for displaying no tendency
|
||||
//$second = round($value); //allow for 10% deviation for displaying no tendency
|
||||
$arrowGood = "down";
|
||||
$arrowBad = "up";
|
||||
}else{
|
||||
if($rowPrev[$name] == 0)
|
||||
$dev=100;
|
||||
else
|
||||
$dev = $value/$rowPrev[$name];
|
||||
//$first = round($value); //allow for 10% deviation for displaying no tendency
|
||||
//$second = round($rowPrev[$name]); //allow for 10% deviation for displaying no tendency
|
||||
$arrowGood = "up";
|
||||
$arrowBad = "down";
|
||||
}
|
||||
if($dev > 1.05){
|
||||
$html .= "<span class='float-right text-success-emphasis'>
|
||||
<i class='bi bi-arrow-".$arrowGood."' style='font-size: 0.9em;'></i> ";
|
||||
}elseif($dev < 0.95){
|
||||
$html .= "<span class='float-right text-danger-emphasis'>
|
||||
<i class='bi bi-arrow-".$arrowBad."' style='font-size: 0.9em;'></i> ";
|
||||
}else{
|
||||
$html .= "<span class='float-right'>
|
||||
<i class='bi bi-arrow-right' style='font-size: 0.9em;'></i> ";
|
||||
}
|
||||
}
|
||||
else{
|
||||
$html .= "<span class='float-right'>";
|
||||
}
|
||||
$html .= number_format(floatval($value),2,",",".")
|
||||
."<small> ".$units[$i]."</small></span></div>
|
||||
<!-- /.info-box-content -->
|
||||
</div>
|
||||
</div>";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$html .= "</div>";
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo $html;
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
require_once("../restricted/costs.php");
|
||||
if(!isset($_GET["year"])){
|
||||
$_GET["year"] = date("Y");
|
||||
}else{
|
||||
$_GET["year"] = intval($_GET["year"]);
|
||||
}
|
||||
if($_GET["year"] < 2018 || $_GET["year"] > date("Y")){
|
||||
exit;
|
||||
}
|
||||
if(isset($_GET["type"])){
|
||||
if(strtolower($_GET["type"]) =="lastyear"){
|
||||
$_GET["year"] = date("Y")-1;
|
||||
}elseif(strtolower($_GET["type"]) =="prelastyear"){
|
||||
$_GET["year"] = date("Y")-2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Jahresstatistik als eine Abfrage - jetzt auf stats_daily.
|
||||
*
|
||||
* Gerechnet wird nicht mehr ueber die Rohdaten aus EnergyFlow, sondern ueber
|
||||
* die Tageswerte. Zwei Gruende:
|
||||
*
|
||||
* 1. Die Rohdaten werden nach zwoelf Monaten ausgeduennt bzw. ins
|
||||
* Stundenarchiv verschoben (solarlog-rollup.sh). Eine Kachel, die auf
|
||||
* EnergyFlow rechnet, zeigt fuer alte Jahre danach zu wenig an.
|
||||
* 2. Ein Jahr sind 365 Zeilen statt rund 105.000.
|
||||
*
|
||||
* Die Tarife bleiben unveraendert: je Zeile ein Stichtag, das Ende holt
|
||||
* LEAD() beim naechsten. Weil ein Stichtag ein DATUM ist, kann ein Tag nie
|
||||
* zwei Tarife haben - die Verdichtung auf Tage verliert hier also nichts.
|
||||
*
|
||||
* Was in stats_daily vorberechnet sein MUSS, weil es eine Bedingung je
|
||||
* Messwert auswertet und sich aus Tagessummen nicht rekonstruieren laesst:
|
||||
*
|
||||
* eigenverbrauch_kwh pv - Einspeisung - Batterieladung
|
||||
* - Heizstab + Batterieentladung. Dazu addiert
|
||||
* wird pv_fehlbetrag_kwh: bei Ausfall einzelner
|
||||
* Wechselrichter fehlt deren Beitrag in pv, alle
|
||||
* Senken sind dagegen gemessen - die Differenz
|
||||
* faellt sonst zu klein oder negativ aus.
|
||||
* heizstab_solar_kwh Heizstab, anteilig nach autonomy
|
||||
* auto_*_solar_kwh Wallbox, anteilig nach autonomy - dem vom
|
||||
* Geraet in feiner Aufloesung gerechneten
|
||||
* Nicht-Netz-Anteil der Zufuhr
|
||||
*
|
||||
* Einheiten sind in stats_daily bereits bereinigt: PL*_EV und PL*_EVog
|
||||
* liefern Kilowatt, alle uebrigen Leistungsspalten Watt. In der alten
|
||||
* Abfrage stand das als /12 gegen /12000 nebeneinander.
|
||||
*
|
||||
* Die Solaranteile teilen jetzt durch NULLIF(...): ohne Ladung im Jahr kam
|
||||
* vorher 0/0 heraus.
|
||||
*
|
||||
* "Ersparnis Batterie" rechnet den Nutzen netto: was die entladene Energie
|
||||
* aus dem Netz gekostet haette, abzueglich der Verguetung, die fuer den zum
|
||||
* Laden verwendeten Strom entgangen ist. Brutto waere die Kachel zu
|
||||
* freundlich - der Speicher ist nicht umsonst zu fuellen.
|
||||
*
|
||||
* Achtung beim Lesen: "Verbrauchsersparnis" ist der GESAMTE Eigenverbrauch
|
||||
* zum Strompreis. "Ersparnis Batterie" und "Ersparnis Solarladung" sind
|
||||
* Teilmengen davon, nach Herkunft bzw. Verwendung herausgegriffen. Sie
|
||||
* duerfen nicht addiert werden.
|
||||
*
|
||||
* Der Grundpreis fehlt weiterhin bewusst - er haengt an den Tagen des
|
||||
* Jahres, nicht an einem Messwert, und kommt aus grundpreisImJahr() dazu.
|
||||
*/
|
||||
function statistikAbfrage($jahr)
|
||||
{
|
||||
return "WITH
|
||||
preis AS (SELECT active_date, cost, gain,
|
||||
LEAD(active_date) OVER (ORDER BY active_date) AS folgt FROM gridCosts),
|
||||
gas AS (SELECT active_date, cost, kwhPerLitre,
|
||||
LEAD(active_date) OVER (ORDER BY active_date) AS folgt FROM gasCosts),
|
||||
sprit AS (SELECT active_date, cost, lPer100km, kwhPer100km,
|
||||
LEAD(active_date) OVER (ORDER BY active_date) AS folgt FROM fuelCosts)
|
||||
SELECT
|
||||
SUM(d.netz_bezug_kwh) AS 'Stromverbrauch',
|
||||
SUM(d.netz_bezug_kwh * preis.cost) AS 'Stromkosten',
|
||||
SUM((d.eigenverbrauch_kwh + IFNULL(d.pv_fehlbetrag_kwh,0)) * preis.cost) AS 'Verbrauchsersparnis',
|
||||
SUM(d.netz_einsp_kwh * preis.gain) AS 'Einspeisevergütung',
|
||||
SUM(d.heizstab_solar_kwh * gas.cost / NULLIF(gas.kwhPerLitre,0)) AS 'Ersparnis Heizung',
|
||||
SUM(d.batt_entladen_kwh * preis.cost - d.batt_laden_kwh * preis.gain) AS 'Ersparnis Batterie',
|
||||
SUM(d.autarkie_avg * d.stunden_erfasst) / NULLIF(SUM(d.stunden_erfasst),0) AS 'Ø Autarkie',
|
||||
SUM(d.auto_eg_kwh) AS 'Autoladung ges. EG',
|
||||
SUM(d.auto_eg_solar_kwh) / NULLIF(SUM(d.auto_eg_kwh),0) * 100 AS 'Autoladung Solar EG',
|
||||
SUM(d.auto_eg_solar_kwh * preis.cost) AS 'Ersparnis Solarladung EG',
|
||||
SUM(d.auto_eg_kwh * sprit.lPer100km / NULLIF(sprit.kwhPer100km,0)) AS 'Benzin gespart EG',
|
||||
SUM(d.auto_eg_kwh * sprit.lPer100km / NULLIF(sprit.kwhPer100km,0) * sprit.cost) AS 'Ersparnis Benzin EG',
|
||||
SUM(d.auto_og_kwh) AS 'Autoladung ges. OG',
|
||||
SUM(d.auto_og_solar_kwh) / NULLIF(SUM(d.auto_og_kwh),0) * 100 AS 'Autoladung Solar OG',
|
||||
SUM(d.auto_og_solar_kwh * preis.cost) AS 'Ersparnis Solarladung OG',
|
||||
SUM(d.auto_og_kwh * sprit.lPer100km / NULLIF(sprit.kwhPer100km,0)) AS 'Benzin gespart OG',
|
||||
SUM(d.auto_og_kwh * sprit.lPer100km / NULLIF(sprit.kwhPer100km,0) * sprit.cost) AS 'Ersparnis Benzin OG'
|
||||
FROM stats_daily d
|
||||
JOIN preis ON d.tag >= preis.active_date AND (preis.folgt IS NULL OR d.tag < preis.folgt)
|
||||
LEFT JOIN gas ON d.tag >= gas.active_date AND (gas.folgt IS NULL OR d.tag < gas.folgt)
|
||||
LEFT JOIN sprit ON d.tag >= sprit.active_date AND (sprit.folgt IS NULL OR d.tag < sprit.folgt)
|
||||
WHERE YEAR(d.tag) = " . intval($jahr) . ";";
|
||||
}
|
||||
|
||||
$Query = statistikAbfrage($_GET["year"]);
|
||||
$PrevQuery = statistikAbfrage($_GET["year"] - 1);
|
||||
|
||||
// Reihenfolge wie in der Abfrage, mit "Verg.+Einsp. Strom" an Stelle 4.
|
||||
$units = Array("kWh","€","€","€","€","€","€","%",
|
||||
"kWh","%","€","L","€",
|
||||
"kWh","%","€","L","€");
|
||||
// Nur bei Verbrauch und Kosten ist weniger besser.
|
||||
$LessIsBetter = array_merge([true, true], array_fill(0, count($units) - 2, false));
|
||||
|
||||
function array_insert($array,$values,$offset) {
|
||||
return array_slice($array, 0, $offset, true) + $values + array_slice($array, $offset, NULL, true);
|
||||
}
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
|
||||
$html = "<div class='row row-cols-2 row-cols-md-4 g-2 row-info'>";
|
||||
$mysql = solarDb();
|
||||
$Res = mysqli_query($mysql,$Query);
|
||||
$ResPrev = mysqli_query($mysql,$PrevQuery);
|
||||
if(!$Res || !$ResPrev){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
if ($Res->num_rows > 0) {
|
||||
$i = 0;
|
||||
$row = $Res->fetch_assoc();
|
||||
$rowPrev = $ResPrev->fetch_assoc();
|
||||
// Der Grundpreis faellt unabhaengig vom Verbrauch an und laesst sich
|
||||
// deshalb nicht aus den Messwerten summieren.
|
||||
$row["Stromkosten"] += grundpreisImJahr($_GET["year"]);
|
||||
$rowPrev["Stromkosten"] += grundpreisImJahr($_GET["year"] - 1);
|
||||
//$row["Vergütung+Einsparung Strom"] = $row["Einspeisevergütung"]+$row["Verbrauchsersparnis"];
|
||||
$row = array_insert($row,["Verg.+Einsp. Strom" => $row["Einspeisevergütung"]+$row["Verbrauchsersparnis"]],4);
|
||||
$rowPrev = array_insert($rowPrev,["Verg.+Einsp. Strom" => $rowPrev["Einspeisevergütung"]+$rowPrev["Verbrauchsersparnis"]],4);
|
||||
$i = 0;
|
||||
foreach ($row as $name => $value) {
|
||||
if(str_starts_with($name,"Autoladung ges.")){
|
||||
$html .= "</div><hr class='mt-3 mb-3 border-light' />";
|
||||
$html .= "<div class='row row-cols-2 row-cols-md-4 g-2 row-info'>";
|
||||
}
|
||||
/*$html .= "<div class='col-12 col-sm-4 col-md-2 col-xl-1'>
|
||||
<div class='info-box'>
|
||||
<div class='info-box-content'>
|
||||
<span class='info-box-text'>".$name."</span>
|
||||
<span class='info-box-number'>".
|
||||
number_format(floatval($value),2,",",".")
|
||||
."<small>".$units[$i++]."</small>
|
||||
</span>
|
||||
</div>
|
||||
<!-- /.info-box-content -->
|
||||
</div>
|
||||
</div>";*/
|
||||
$html .= "<div class='col'>
|
||||
<div class='card stats border-0'>
|
||||
<div class='card-body bg-dark bg-gradient rounded-top pb-1 pt-1'>
|
||||
".$name."
|
||||
</div>
|
||||
<div class='card-footer text-center'>";
|
||||
if($_GET["year"] != date("Y")){
|
||||
if($LessIsBetter[$i]){
|
||||
if($value == 0)
|
||||
$dev=100;
|
||||
else
|
||||
$dev = $rowPrev[$name]/$value;
|
||||
//$first = round($rowPrev[$name]*10/$rowPrev[$name]); //allow for 10% deviation for displaying no tendency
|
||||
//$second = round($value); //allow for 10% deviation for displaying no tendency
|
||||
$arrowGood = "down";
|
||||
$arrowBad = "up";
|
||||
}else{
|
||||
if($rowPrev[$name] == 0)
|
||||
$dev=100;
|
||||
else
|
||||
$dev = $value/$rowPrev[$name];
|
||||
//$first = round($value); //allow for 10% deviation for displaying no tendency
|
||||
//$second = round($rowPrev[$name]); //allow for 10% deviation for displaying no tendency
|
||||
$arrowGood = "up";
|
||||
$arrowBad = "down";
|
||||
}
|
||||
if($dev > 1.05){
|
||||
$html .= "<span class='float-right text-success-emphasis'>
|
||||
<i class='bi bi-arrow-".$arrowGood."' style='font-size: 0.9em;'></i> ";
|
||||
}elseif($dev < 0.95){
|
||||
$html .= "<span class='float-right text-danger-emphasis'>
|
||||
<i class='bi bi-arrow-".$arrowBad."' style='font-size: 0.9em;'></i> ";
|
||||
}else{
|
||||
$html .= "<span class='float-right'>
|
||||
<i class='bi bi-arrow-right' style='font-size: 0.9em;'></i> ";
|
||||
}
|
||||
}
|
||||
else{
|
||||
$html .= "<span class='float-right'>";
|
||||
}
|
||||
$html .= number_format(floatval($value),2,",",".")
|
||||
."<small> ".$units[$i]."</small></span></div>
|
||||
<!-- /.info-box-content -->
|
||||
</div>
|
||||
</div>";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$html .= "</div>";
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo $html;
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
|
||||
+65
-65
@@ -1,65 +1,65 @@
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
if(!isset($_GET["TO"])){
|
||||
$_GET["TO"] = 12;
|
||||
}
|
||||
$_GET["TO"] = intval($_GET["TO"]);
|
||||
if(!isset($_GET["FROM"])){
|
||||
$_GET["FROM"] = -24;
|
||||
}
|
||||
$_GET["FROM"] = intval($_GET["FROM"]);
|
||||
|
||||
$Query = "SELECT
|
||||
UNIX_TIMESTAMP(CONCAT(date,' ',sunrise)) AS sunrise,
|
||||
UNIX_TIMESTAMP(CONCAT(date,' ',sunset)) AS sunset
|
||||
FROM solarLog.daylight
|
||||
WHERE date BETWEEN DATE_ADD(NOW(),INTERVAL ".($_GET["FROM"]-24)." HOUR) and DATE_ADD(NOW(),INTERVAL ".$_GET["TO"]." HOUR)
|
||||
ORDER BY date";
|
||||
|
||||
$linecolors["Solarleistung"] = "#FFFF00";
|
||||
$linecolors["UG"] = "#FFaa00";
|
||||
$linecolors["OG"] = "#FF4400";
|
||||
$linecolors["Auto UG"] = "#00aaFF";
|
||||
$linecolors["Auto OG"] = "#0044FF";
|
||||
$linecolors["Heizstab"] = "#FF0000";
|
||||
$linecolors["Batterieladung"] = "#00aa00";
|
||||
$linecolors["Einspeisung"] = "#b0b0b0";
|
||||
$linecolors["Ladestand"] = "#00aa00";
|
||||
$linecolors["Vorhersage"] = "#2222FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$result = mysqli_query($mysql, $Query);
|
||||
if (!$result) {
|
||||
echo "Error:<br>" . mysqli_error($mysql) . "<br />";
|
||||
}
|
||||
//$obj[] = (object)[]; // Cast empty array to object
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$ii = 1;
|
||||
$anno = (object)[];
|
||||
if($row["sunrise"] < (time()+$_GET["FROM"]*60*60)){
|
||||
$anno->xMin = (time()+$_GET["FROM"]*60*60)*1000;
|
||||
}else{
|
||||
$anno->xMin = $row["sunrise"]*1000;
|
||||
}
|
||||
if($row["sunset"] > (time()+$_GET["TO"]*60*60)){
|
||||
$anno->xMax = round(time()+$_GET["TO"]*60*60)*1000;
|
||||
}else{
|
||||
$anno->xMax = $row["sunset"]*1000;
|
||||
}
|
||||
$anno->borderWidth = 0;
|
||||
if($row["sunset"] > (time()+$_GET["FROM"]*60*60)){
|
||||
$obj[] = clone $anno;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
if(!isset($_GET["TO"])){
|
||||
$_GET["TO"] = 12;
|
||||
}
|
||||
$_GET["TO"] = intval($_GET["TO"]);
|
||||
if(!isset($_GET["FROM"])){
|
||||
$_GET["FROM"] = -24;
|
||||
}
|
||||
$_GET["FROM"] = intval($_GET["FROM"]);
|
||||
|
||||
$Query = "SELECT
|
||||
UNIX_TIMESTAMP(CONCAT(date,' ',sunrise)) AS sunrise,
|
||||
UNIX_TIMESTAMP(CONCAT(date,' ',sunset)) AS sunset
|
||||
FROM solarLog.daylight
|
||||
WHERE date BETWEEN DATE_ADD(NOW(),INTERVAL ".($_GET["FROM"]-24)." HOUR) and DATE_ADD(NOW(),INTERVAL ".$_GET["TO"]." HOUR)
|
||||
ORDER BY date";
|
||||
|
||||
$linecolors["Solarleistung"] = "#FFFF00";
|
||||
$linecolors["UG"] = "#FFaa00";
|
||||
$linecolors["OG"] = "#FF4400";
|
||||
$linecolors["Auto UG"] = "#00aaFF";
|
||||
$linecolors["Auto OG"] = "#0044FF";
|
||||
$linecolors["Heizstab"] = "#FF0000";
|
||||
$linecolors["Batterieladung"] = "#00aa00";
|
||||
$linecolors["Einspeisung"] = "#b0b0b0";
|
||||
$linecolors["Ladestand"] = "#00aa00";
|
||||
$linecolors["Vorhersage"] = "#2222FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$result = mysqli_query($mysql, $Query);
|
||||
if (!$result) {
|
||||
echo "Error:<br>" . mysqli_error($mysql) . "<br />";
|
||||
}
|
||||
//$obj[] = (object)[]; // Cast empty array to object
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$ii = 1;
|
||||
$anno = (object)[];
|
||||
if($row["sunrise"] < (time()+$_GET["FROM"]*60*60)){
|
||||
$anno->xMin = (time()+$_GET["FROM"]*60*60)*1000;
|
||||
}else{
|
||||
$anno->xMin = $row["sunrise"]*1000;
|
||||
}
|
||||
if($row["sunset"] > (time()+$_GET["TO"]*60*60)){
|
||||
$anno->xMax = round(time()+$_GET["TO"]*60*60)*1000;
|
||||
}else{
|
||||
$anno->xMax = $row["sunset"]*1000;
|
||||
}
|
||||
$anno->borderWidth = 0;
|
||||
if($row["sunset"] > (time()+$_GET["FROM"]*60*60)){
|
||||
$obj[] = clone $anno;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
|
||||
+65
-65
@@ -1,65 +1,65 @@
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
|
||||
$waterQuery = "SELECT UNIX_TIMESTAMP(datetime) AS time, rate AS 'Wasserverbrauch'
|
||||
FROM solarLog.wasser
|
||||
WHERE wasser.datetime BETWEEN DATE_SUB(NOW(),INTERVAL 24 HOUR) and NOW()
|
||||
ORDER BY wasser.datetime";
|
||||
|
||||
$linecolors["Speicher oben"] = "#FF5500";
|
||||
$linecolors["Speicher mitte"] = "#FFaa00";
|
||||
$linecolors["Speicher unten"] = "#FFFF00";
|
||||
$linecolors["Therme Vorlauf Fußboden"] = "#bb0000";
|
||||
$linecolors["Therme Rücklauf"] = "#ee0000";
|
||||
$linecolors["Heizstab Vorlauf"] = "#9900bb";
|
||||
$linecolors["Heizstab Rücklauf"] = "#8800aa";
|
||||
$linecolors["Fußboden Vorlauf"] = "#00FF00";
|
||||
$linecolors["Fußboden Rücklauf"] = "#00aa00";
|
||||
$linecolors["Wasserverbrauch"] = "#2222FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$waterRes = mysqli_query($mysql,$waterQuery);
|
||||
if(!$waterRes){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
$obj = (object)[]; // Cast empty array to object
|
||||
$obj->labels = [];
|
||||
$obj->datasets = [];
|
||||
$i = 0;
|
||||
$filled = 0;
|
||||
if ($waterRes->num_rows > 1) {
|
||||
$dataset = (object)[];
|
||||
$row = $waterRes->fetch_assoc();
|
||||
$dataset->borderColor = $linecolors["Wasserverbrauch"];
|
||||
$dataset->backgroundColor = $linecolors["Wasserverbrauch"]."00";
|
||||
$dataset->borderWidth=2;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y1';
|
||||
$dataset->label = "Wasserverbrauch";
|
||||
$pt = (object)[];
|
||||
$pt->x = $row["time"]*1000;
|
||||
$pt->y = $row["Wasserverbrauch"];
|
||||
$dataset->data[] = clone $pt;
|
||||
while ($row = $waterRes->fetch_assoc()) {
|
||||
$pt = (object)[];
|
||||
$pt->x = $row["time"]*1000;
|
||||
$pt->y = $row["Wasserverbrauch"];
|
||||
$dataset->data[] = clone $pt;
|
||||
}
|
||||
$obj->datasets[] = clone $dataset;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
|
||||
$waterQuery = "SELECT UNIX_TIMESTAMP(datetime) AS time, rate AS 'Wasserverbrauch'
|
||||
FROM solarLog.wasser
|
||||
WHERE wasser.datetime BETWEEN DATE_SUB(NOW(),INTERVAL 24 HOUR) and NOW()
|
||||
ORDER BY wasser.datetime";
|
||||
|
||||
$linecolors["Speicher oben"] = "#FF5500";
|
||||
$linecolors["Speicher mitte"] = "#FFaa00";
|
||||
$linecolors["Speicher unten"] = "#FFFF00";
|
||||
$linecolors["Therme Vorlauf Fußboden"] = "#bb0000";
|
||||
$linecolors["Therme Rücklauf"] = "#ee0000";
|
||||
$linecolors["Heizstab Vorlauf"] = "#9900bb";
|
||||
$linecolors["Heizstab Rücklauf"] = "#8800aa";
|
||||
$linecolors["Fußboden Vorlauf"] = "#00FF00";
|
||||
$linecolors["Fußboden Rücklauf"] = "#00aa00";
|
||||
$linecolors["Wasserverbrauch"] = "#2222FF";
|
||||
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$mysql = new mysqli($mysql_server, $mysql_solarUser, $mysql_solarPass, $mysql_solarDB);
|
||||
$waterRes = mysqli_query($mysql,$waterQuery);
|
||||
if(!$waterRes){
|
||||
echo "Error:<br>".mysqli_error($mysql)."<br />";
|
||||
}
|
||||
$obj = (object)[]; // Cast empty array to object
|
||||
$obj->labels = [];
|
||||
$obj->datasets = [];
|
||||
$i = 0;
|
||||
$filled = 0;
|
||||
if ($waterRes->num_rows > 1) {
|
||||
$dataset = (object)[];
|
||||
$row = $waterRes->fetch_assoc();
|
||||
$dataset->borderColor = $linecolors["Wasserverbrauch"];
|
||||
$dataset->backgroundColor = $linecolors["Wasserverbrauch"]."00";
|
||||
$dataset->borderWidth=2;
|
||||
$dataset->pointRadius= 0;
|
||||
$dataset->pointHoverRadius= 5;
|
||||
$dataset->tension=0.2;
|
||||
$dataset->fill = "none";
|
||||
$dataset->yAxisID = 'y1';
|
||||
$dataset->label = "Wasserverbrauch";
|
||||
$pt = (object)[];
|
||||
$pt->x = $row["time"]*1000;
|
||||
$pt->y = $row["Wasserverbrauch"];
|
||||
$dataset->data[] = clone $pt;
|
||||
while ($row = $waterRes->fetch_assoc()) {
|
||||
$pt = (object)[];
|
||||
$pt->x = $row["time"]*1000;
|
||||
$pt->y = $row["Wasserverbrauch"];
|
||||
$dataset->data[] = clone $pt;
|
||||
}
|
||||
$obj->datasets[] = clone $dataset;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//header('Content-Type: application/json');
|
||||
echo json_encode($obj);
|
||||
//echo '{"labels":[1761322682000,1761322782000,1761322882000,1761322982000,1761323082000,1761323182000,1761323282000],"datasets":[{"stack": "Stack 0","cubicInterpolationMode":"monotone","fill":"origin","label":"Acquisitions by year","data":[10,20,50,20,10,5,70]},{"fill": "false","stack": "Stack 1","cubicInterpolationMode": "monotone","label": "Acquisitions by year","data": [10,20,50,20,10,5,70]}]}';
|
||||
|
||||
+57
-57
@@ -1,57 +1,57 @@
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$close = 0;
|
||||
$hostname = "192.168.179.169";
|
||||
|
||||
|
||||
if (isset($_POST["setMode"]) || isset($_GET["setMode"])) {
|
||||
//send new value
|
||||
$_POST["setMode"] = intval($_POST["setMode"]) + intval($_GET["setMode"]);
|
||||
if($_POST["setMode"] > 0 && $_POST["setMode"] < 60){
|
||||
$pwr = $_POST["setMode"]*100;
|
||||
$headers[] = "GET /set?mode=man&pwr=".$pwr." HTTP/1.1";
|
||||
$headers[] = "Host: ".$hostname;
|
||||
$headers[] = "";
|
||||
$remote = fsockopen("tcp://".$hostname, 80, $errno, $errstr, 5);
|
||||
fwrite($remote, implode("\r\n", $headers)."\r\n");
|
||||
$file = '';
|
||||
$file .= fread($remote, 1024);
|
||||
fclose($remote);
|
||||
}elseif($_POST["setMode"] == 0){
|
||||
$headers[] = "GET /set?mode=eco&pwr=0 HTTP/1.1";
|
||||
$headers[] = "Host: ".$hostname;
|
||||
$headers[] = "";
|
||||
$remote = fsockopen("tcp://".$hostname, 80, $errno, $errstr, 5);
|
||||
fwrite($remote, implode("\r\n", $headers)."\r\n");
|
||||
$file = '';
|
||||
$file .= fread($remote, 1024);
|
||||
fclose($remote);
|
||||
}
|
||||
$close = 1;
|
||||
|
||||
}
|
||||
} else {
|
||||
$close = 1;
|
||||
}
|
||||
if (!$close) {
|
||||
echo <<<ENDE
|
||||
<!--begin::Form-->
|
||||
<form id="heater_form">
|
||||
<div class="col-sm-11">
|
||||
<div class="form-check">
|
||||
<label class="form-label" for="addedCharge">Leistung: </label>
|
||||
<div style="font-size: 15px;color: #297195;display: inline-block;" id="modal-slider-label">0</div>
|
||||
<input type="range" id="modal-slider" name="setMode" class="form-range range-color-track" min="0" max="60" />
|
||||
<div class="d-flex justify-content-between">
|
||||
<span class="max-amount f-16 font-weight-normal darkGray-color text-right mt-1">Auto</span>
|
||||
<span class="max-amount f-16 font-weight-normal darkGray-color text-right mt-1">6.0 kW</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
ENDE;
|
||||
}
|
||||
<?php
|
||||
|
||||
require_once("../helper.php");
|
||||
|
||||
|
||||
if (checkLogin()) {
|
||||
$close = 0;
|
||||
$hostname = "192.168.179.169";
|
||||
|
||||
|
||||
if (isset($_POST["setMode"]) || isset($_GET["setMode"])) {
|
||||
//send new value
|
||||
$_POST["setMode"] = intval($_POST["setMode"]) + intval($_GET["setMode"]);
|
||||
if($_POST["setMode"] > 0 && $_POST["setMode"] < 60){
|
||||
$pwr = $_POST["setMode"]*100;
|
||||
$headers[] = "GET /set?mode=man&pwr=".$pwr." HTTP/1.1";
|
||||
$headers[] = "Host: ".$hostname;
|
||||
$headers[] = "";
|
||||
$remote = fsockopen("tcp://".$hostname, 80, $errno, $errstr, 5);
|
||||
fwrite($remote, implode("\r\n", $headers)."\r\n");
|
||||
$file = '';
|
||||
$file .= fread($remote, 1024);
|
||||
fclose($remote);
|
||||
}elseif($_POST["setMode"] == 0){
|
||||
$headers[] = "GET /set?mode=eco&pwr=0 HTTP/1.1";
|
||||
$headers[] = "Host: ".$hostname;
|
||||
$headers[] = "";
|
||||
$remote = fsockopen("tcp://".$hostname, 80, $errno, $errstr, 5);
|
||||
fwrite($remote, implode("\r\n", $headers)."\r\n");
|
||||
$file = '';
|
||||
$file .= fread($remote, 1024);
|
||||
fclose($remote);
|
||||
}
|
||||
$close = 1;
|
||||
|
||||
}
|
||||
} else {
|
||||
$close = 1;
|
||||
}
|
||||
if (!$close) {
|
||||
echo <<<ENDE
|
||||
<!--begin::Form-->
|
||||
<form id="heater_form">
|
||||
<div class="col-sm-11">
|
||||
<div class="form-check">
|
||||
<label class="form-label" for="addedCharge">Leistung: </label>
|
||||
<div style="font-size: 15px;color: #297195;display: inline-block;" id="modal-slider-label">0</div>
|
||||
<input type="range" id="modal-slider" name="setMode" class="form-range range-color-track" min="0" max="60" />
|
||||
<div class="d-flex justify-content-between">
|
||||
<span class="max-amount f-16 font-weight-normal darkGray-color text-right mt-1">Auto</span>
|
||||
<span class="max-amount f-16 font-weight-normal darkGray-color text-right mt-1">6.0 kW</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
ENDE;
|
||||
}
|
||||
|
||||
+671
-671
File diff suppressed because it is too large
Load Diff
+252
-252
@@ -1,252 +1,252 @@
|
||||
<?php
|
||||
set_time_limit(60);
|
||||
ob_start();
|
||||
require_once("../helper.php");
|
||||
require_once("../restricted/tahoma_EG.php");
|
||||
|
||||
// Ohne diese Pruefung liessen sich Rollladen von beliebiger Stelle abfragen
|
||||
// und verfahren - das Tahoma-Token liegt serverseitig, ein Angreifer braucht
|
||||
// es also gar nicht.
|
||||
if (!checkLogin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
//67ebd23e3a61763386d9
|
||||
function getSSLPage($url, $tahoma_token)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', "Authorization: Bearer ".$tahoma_token));
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$error_msg = curl_error($ch);
|
||||
//print $error_msg;
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function postSSLPage($url, $body, $tahoma_token)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', "Authorization: Bearer ".$tahoma_token));
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$error_msg = curl_error($ch);
|
||||
//print $error_msg;
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function filter_devs($arr,$filter,$prefix=""){
|
||||
$ret = Array();
|
||||
$i = 0;
|
||||
foreach($arr as $key => $dev){
|
||||
$start = strpos(strtolower($dev["name"]),strtolower($filter));
|
||||
if($start !== false){
|
||||
$dev["name"] = str_replace("u_","",$dev["name"]);
|
||||
$ret[$i]["name"] = $prefix.substr($dev["name"],strlen($filter));
|
||||
$ret[$i]["id"] = $key;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function searchForDevice($device){
|
||||
$dev = false;
|
||||
$devices = json_decode(file_get_contents($GLOBALS["tahoma_devlist"]), true);
|
||||
if (strlen($device) < 3 && intval($device) >= 0 && intval($device) < sizeof($devices)) {
|
||||
$dev = $devices[intval($device)];
|
||||
} else if ($key = array_search($device, array_column($devices, "name"))) {
|
||||
$dev = $devices[$key];
|
||||
} else if ($key = array_search($device, array_column($devices, "id"))) {
|
||||
$dev = $devices[$key];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return $dev;
|
||||
}
|
||||
|
||||
if ($_GET["action"] == "devlist") {
|
||||
$jalousien = array();
|
||||
$url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/setup/devices';
|
||||
$ret = getSSLPage($url,$tahoma_token);
|
||||
$devices = json_decode($ret, true);
|
||||
$i = 0;
|
||||
foreach ($devices as $device) {
|
||||
if ($device["controllableName"] == "io:ExteriorVenetianBlindIOComponent") {
|
||||
$jalousien[$i]["name"] = $device["label"];
|
||||
$jalousien[$i]["id"] = $device["deviceURL"];
|
||||
$i = $i + 1;
|
||||
echo $device["label"] . "(".$device["deviceURL"].")<br />";
|
||||
}
|
||||
}
|
||||
//$file = fopen($tahoma_devlist, 'w');
|
||||
//fwrite($file, json_encode($jalousien));
|
||||
//fclose($file);
|
||||
echo json_encode($jalousien);
|
||||
}elseif ($_GET["action"] == "pos" && isset($_GET["device"])) {
|
||||
$dev = searchForDevice($_GET["device"])["id"];
|
||||
$devices = json_decode(file_get_contents($tahoma_devlist), true);
|
||||
$jalousien = array();
|
||||
$url = $url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/setup/devices/'.urlencode($dev)."/states";
|
||||
$ret = getSSLPage($url,$tahoma_token);
|
||||
$states = json_decode($ret, true);
|
||||
$out = "{";
|
||||
foreach ($states as $state){
|
||||
if ($state["name"] == "core:SlateOrientationState")
|
||||
$out .= "\"rotation\":".$state["value"].",";
|
||||
if ($state["name"] == "core:ClosureState")
|
||||
$out .= "\"position\":".$state["value"].",";
|
||||
}
|
||||
$out = substr($out,0,-1);
|
||||
$out .= "}";
|
||||
echo $out;
|
||||
header('Connection: close');
|
||||
header('Content-Length: '.ob_get_length());
|
||||
ob_end_flush();
|
||||
@ob_flush();
|
||||
flush();
|
||||
fastcgi_finish_request();
|
||||
}elseif ($_GET["action"] == "moving" && isset($_GET["device"])) {
|
||||
$dev = searchForDevice($_GET["device"])["id"];
|
||||
$devices = json_decode(file_get_contents($tahoma_devlist), true);
|
||||
$jalousien = array();
|
||||
$url = $url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/setup/devices/'.urlencode($dev)."/states/core:MovingState";
|
||||
$ret = getSSLPage($url,$tahoma_token);
|
||||
$moving = json_decode($ret, true);
|
||||
if($moving["value"])
|
||||
echo "true";
|
||||
else
|
||||
echo "false";
|
||||
header('Connection: close');
|
||||
header('Content-Length: '.ob_get_length());
|
||||
ob_end_flush();
|
||||
@ob_flush();
|
||||
flush();
|
||||
fastcgi_finish_request();
|
||||
}elseif ($_GET["action"] == "move" && isset($_GET["pos"]) && isset($_GET["angle"]) && isset($_GET["device"])) {
|
||||
$angle = $_GET["angle"];
|
||||
$pos = $_GET["pos"];
|
||||
if ($pos < 0 || $pos > 100) {
|
||||
echo "Position out of Range";
|
||||
exit;
|
||||
}
|
||||
if ($angle < 0 || $angle > 100) {
|
||||
echo "Angle out of Range";
|
||||
exit;
|
||||
}
|
||||
$dev = searchForDevice($_GET["device"])["id"];
|
||||
if($dev == false){
|
||||
exit;
|
||||
}
|
||||
header('Connection: close');
|
||||
header('Content-Length: '.ob_get_length());
|
||||
$url = $url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/setup/devices/'.urlencode($dev)."/states/core:MovingState";
|
||||
$ret = json_decode(getSSLPage($url,$tahoma_token),true);
|
||||
|
||||
$action = array();
|
||||
$action["label"] = "myAction";
|
||||
$action["actions"] = array();
|
||||
$action["actions"][0]["deviceURL"] = $dev;
|
||||
$action["actions"][0]["commands"] = array();
|
||||
if(!isset($ret["value"])){
|
||||
$ret = json_decode(getSSLPage($url,$tahoma_token),true);
|
||||
}
|
||||
|
||||
if(!isset($ret["value"]) || $ret["value"] == false){
|
||||
$url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/exec/apply';
|
||||
echo "start";
|
||||
ob_end_flush();
|
||||
@ob_flush();
|
||||
flush();
|
||||
fastcgi_finish_request();
|
||||
$action["actions"][0]["commands"][0]["name"] = "setClosureAndOrientation";
|
||||
$action["actions"][0]["commands"][0]["parameters"][0] = intval($pos);
|
||||
$action["actions"][0]["commands"][0]["parameters"][1] = intval($angle);
|
||||
$res = json_decode(postSSLPage($url,json_encode($action),$tahoma_token));
|
||||
if(!isset($res["execId"])){
|
||||
sleep(1);
|
||||
$res = json_decode(postSSLPage($url,json_encode($action),$tahoma_token)); //2nd try
|
||||
}
|
||||
}elseif($ret["value"] == true){
|
||||
$url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/exec/apply';
|
||||
echo "stop";
|
||||
ob_end_flush();
|
||||
@ob_flush();
|
||||
flush();
|
||||
fastcgi_finish_request();
|
||||
$action["actions"][0]["commands"][0]["name"] = "stop";
|
||||
$res = json_decode(postSSLPage($url,json_encode($action),$tahoma_token));
|
||||
if(!isset($res["execId"])){
|
||||
sleep(1);
|
||||
$res = json_decode(postSSLPage($url,json_encode($action),$tahoma_token)); //2nd try
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ($_GET["action"] == "myactors") {
|
||||
if(isset($_GET["filter"])){
|
||||
$host = $_GET["filter"];
|
||||
$host = str_replace("-", "", strtolower($host));
|
||||
}else{
|
||||
$host = gethostbyaddr("192.168.179.32");
|
||||
$host = str_replace("-", "", strtolower(substr($host, 0, strpos($host, "."))));
|
||||
}
|
||||
$devices = json_decode(file_get_contents($tahoma_devlist), true);
|
||||
switch ($host) {
|
||||
case "tmpegbad":
|
||||
echo json_encode(filter_devs($devices, "bad "));
|
||||
break;
|
||||
case "tmpegwozi":
|
||||
echo json_encode(filter_devs($devices, "wozi "));
|
||||
break;
|
||||
case "tmpegflorian": //flori
|
||||
$ret = filter_devs($devices, "florian ","Flori ");
|
||||
$ret = array_merge($ret, filter_devs($devices, "magdalena ","Magdalena "));
|
||||
echo json_encode($ret);
|
||||
break;
|
||||
case "tmpegmagdalena":
|
||||
echo json_encode(filter_devs($devices, "magdalena "));
|
||||
break;
|
||||
case "tmpegschlafzimmer":
|
||||
echo json_encode(filter_devs($devices, "schlafzimmer "));
|
||||
break;
|
||||
default:
|
||||
$ret2=Array();
|
||||
//$ret2[0]["name"] = $host;
|
||||
//$ret2[0]["id"] = 99;
|
||||
$ret = filter_devs($devices, "");
|
||||
//$ret = array_merge($ret, $ret2);
|
||||
echo json_encode($ret);
|
||||
break;
|
||||
}
|
||||
header('Connection: close');
|
||||
header('Content-Length: '.ob_get_length());
|
||||
ob_end_flush();
|
||||
@ob_flush();
|
||||
flush();
|
||||
fastcgi_finish_request();
|
||||
|
||||
|
||||
//echo postSSLPage($url,json_encode($action));
|
||||
}
|
||||
<?php
|
||||
set_time_limit(60);
|
||||
ob_start();
|
||||
require_once("../helper.php");
|
||||
require_once("../restricted/tahoma_EG.php");
|
||||
|
||||
// Ohne diese Pruefung liessen sich Rollladen von beliebiger Stelle abfragen
|
||||
// und verfahren - das Tahoma-Token liegt serverseitig, ein Angreifer braucht
|
||||
// es also gar nicht.
|
||||
if (!checkLogin()) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
//67ebd23e3a61763386d9
|
||||
function getSSLPage($url, $tahoma_token)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', "Authorization: Bearer ".$tahoma_token));
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$error_msg = curl_error($ch);
|
||||
//print $error_msg;
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function postSSLPage($url, $body, $tahoma_token)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', "Authorization: Bearer ".$tahoma_token));
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$error_msg = curl_error($ch);
|
||||
//print $error_msg;
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function filter_devs($arr,$filter,$prefix=""){
|
||||
$ret = Array();
|
||||
$i = 0;
|
||||
foreach($arr as $key => $dev){
|
||||
$start = strpos(strtolower($dev["name"]),strtolower($filter));
|
||||
if($start !== false){
|
||||
$dev["name"] = str_replace("u_","",$dev["name"]);
|
||||
$ret[$i]["name"] = $prefix.substr($dev["name"],strlen($filter));
|
||||
$ret[$i]["id"] = $key;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function searchForDevice($device){
|
||||
$dev = false;
|
||||
$devices = json_decode(file_get_contents($GLOBALS["tahoma_devlist"]), true);
|
||||
if (strlen($device) < 3 && intval($device) >= 0 && intval($device) < sizeof($devices)) {
|
||||
$dev = $devices[intval($device)];
|
||||
} else if ($key = array_search($device, array_column($devices, "name"))) {
|
||||
$dev = $devices[$key];
|
||||
} else if ($key = array_search($device, array_column($devices, "id"))) {
|
||||
$dev = $devices[$key];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return $dev;
|
||||
}
|
||||
|
||||
if ($_GET["action"] == "devlist") {
|
||||
$jalousien = array();
|
||||
$url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/setup/devices';
|
||||
$ret = getSSLPage($url,$tahoma_token);
|
||||
$devices = json_decode($ret, true);
|
||||
$i = 0;
|
||||
foreach ($devices as $device) {
|
||||
if ($device["controllableName"] == "io:ExteriorVenetianBlindIOComponent") {
|
||||
$jalousien[$i]["name"] = $device["label"];
|
||||
$jalousien[$i]["id"] = $device["deviceURL"];
|
||||
$i = $i + 1;
|
||||
echo $device["label"] . "(".$device["deviceURL"].")<br />";
|
||||
}
|
||||
}
|
||||
//$file = fopen($tahoma_devlist, 'w');
|
||||
//fwrite($file, json_encode($jalousien));
|
||||
//fclose($file);
|
||||
echo json_encode($jalousien);
|
||||
}elseif ($_GET["action"] == "pos" && isset($_GET["device"])) {
|
||||
$dev = searchForDevice($_GET["device"])["id"];
|
||||
$devices = json_decode(file_get_contents($tahoma_devlist), true);
|
||||
$jalousien = array();
|
||||
$url = $url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/setup/devices/'.urlencode($dev)."/states";
|
||||
$ret = getSSLPage($url,$tahoma_token);
|
||||
$states = json_decode($ret, true);
|
||||
$out = "{";
|
||||
foreach ($states as $state){
|
||||
if ($state["name"] == "core:SlateOrientationState")
|
||||
$out .= "\"rotation\":".$state["value"].",";
|
||||
if ($state["name"] == "core:ClosureState")
|
||||
$out .= "\"position\":".$state["value"].",";
|
||||
}
|
||||
$out = substr($out,0,-1);
|
||||
$out .= "}";
|
||||
echo $out;
|
||||
header('Connection: close');
|
||||
header('Content-Length: '.ob_get_length());
|
||||
ob_end_flush();
|
||||
@ob_flush();
|
||||
flush();
|
||||
fastcgi_finish_request();
|
||||
}elseif ($_GET["action"] == "moving" && isset($_GET["device"])) {
|
||||
$dev = searchForDevice($_GET["device"])["id"];
|
||||
$devices = json_decode(file_get_contents($tahoma_devlist), true);
|
||||
$jalousien = array();
|
||||
$url = $url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/setup/devices/'.urlencode($dev)."/states/core:MovingState";
|
||||
$ret = getSSLPage($url,$tahoma_token);
|
||||
$moving = json_decode($ret, true);
|
||||
if($moving["value"])
|
||||
echo "true";
|
||||
else
|
||||
echo "false";
|
||||
header('Connection: close');
|
||||
header('Content-Length: '.ob_get_length());
|
||||
ob_end_flush();
|
||||
@ob_flush();
|
||||
flush();
|
||||
fastcgi_finish_request();
|
||||
}elseif ($_GET["action"] == "move" && isset($_GET["pos"]) && isset($_GET["angle"]) && isset($_GET["device"])) {
|
||||
$angle = $_GET["angle"];
|
||||
$pos = $_GET["pos"];
|
||||
if ($pos < 0 || $pos > 100) {
|
||||
echo "Position out of Range";
|
||||
exit;
|
||||
}
|
||||
if ($angle < 0 || $angle > 100) {
|
||||
echo "Angle out of Range";
|
||||
exit;
|
||||
}
|
||||
$dev = searchForDevice($_GET["device"])["id"];
|
||||
if($dev == false){
|
||||
exit;
|
||||
}
|
||||
header('Connection: close');
|
||||
header('Content-Length: '.ob_get_length());
|
||||
$url = $url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/setup/devices/'.urlencode($dev)."/states/core:MovingState";
|
||||
$ret = json_decode(getSSLPage($url,$tahoma_token),true);
|
||||
|
||||
$action = array();
|
||||
$action["label"] = "myAction";
|
||||
$action["actions"] = array();
|
||||
$action["actions"][0]["deviceURL"] = $dev;
|
||||
$action["actions"][0]["commands"] = array();
|
||||
if(!isset($ret["value"])){
|
||||
$ret = json_decode(getSSLPage($url,$tahoma_token),true);
|
||||
}
|
||||
|
||||
if(!isset($ret["value"]) || $ret["value"] == false){
|
||||
$url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/exec/apply';
|
||||
echo "start";
|
||||
ob_end_flush();
|
||||
@ob_flush();
|
||||
flush();
|
||||
fastcgi_finish_request();
|
||||
$action["actions"][0]["commands"][0]["name"] = "setClosureAndOrientation";
|
||||
$action["actions"][0]["commands"][0]["parameters"][0] = intval($pos);
|
||||
$action["actions"][0]["commands"][0]["parameters"][1] = intval($angle);
|
||||
$res = json_decode(postSSLPage($url,json_encode($action),$tahoma_token));
|
||||
if(!isset($res["execId"])){
|
||||
sleep(1);
|
||||
$res = json_decode(postSSLPage($url,json_encode($action),$tahoma_token)); //2nd try
|
||||
}
|
||||
}elseif($ret["value"] == true){
|
||||
$url = 'https://gateway-'.$tahoma_PIN.':8443/enduser-mobile-web/1/enduserAPI/exec/apply';
|
||||
echo "stop";
|
||||
ob_end_flush();
|
||||
@ob_flush();
|
||||
flush();
|
||||
fastcgi_finish_request();
|
||||
$action["actions"][0]["commands"][0]["name"] = "stop";
|
||||
$res = json_decode(postSSLPage($url,json_encode($action),$tahoma_token));
|
||||
if(!isset($res["execId"])){
|
||||
sleep(1);
|
||||
$res = json_decode(postSSLPage($url,json_encode($action),$tahoma_token)); //2nd try
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ($_GET["action"] == "myactors") {
|
||||
if(isset($_GET["filter"])){
|
||||
$host = $_GET["filter"];
|
||||
$host = str_replace("-", "", strtolower($host));
|
||||
}else{
|
||||
$host = gethostbyaddr("192.168.179.32");
|
||||
$host = str_replace("-", "", strtolower(substr($host, 0, strpos($host, "."))));
|
||||
}
|
||||
$devices = json_decode(file_get_contents($tahoma_devlist), true);
|
||||
switch ($host) {
|
||||
case "tmpegbad":
|
||||
echo json_encode(filter_devs($devices, "bad "));
|
||||
break;
|
||||
case "tmpegwozi":
|
||||
echo json_encode(filter_devs($devices, "wozi "));
|
||||
break;
|
||||
case "tmpegflorian": //flori
|
||||
$ret = filter_devs($devices, "florian ","Flori ");
|
||||
$ret = array_merge($ret, filter_devs($devices, "magdalena ","Magdalena "));
|
||||
echo json_encode($ret);
|
||||
break;
|
||||
case "tmpegmagdalena":
|
||||
echo json_encode(filter_devs($devices, "magdalena "));
|
||||
break;
|
||||
case "tmpegschlafzimmer":
|
||||
echo json_encode(filter_devs($devices, "schlafzimmer "));
|
||||
break;
|
||||
default:
|
||||
$ret2=Array();
|
||||
//$ret2[0]["name"] = $host;
|
||||
//$ret2[0]["id"] = 99;
|
||||
$ret = filter_devs($devices, "");
|
||||
//$ret = array_merge($ret, $ret2);
|
||||
echo json_encode($ret);
|
||||
break;
|
||||
}
|
||||
header('Connection: close');
|
||||
header('Content-Length: '.ob_get_length());
|
||||
ob_end_flush();
|
||||
@ob_flush();
|
||||
flush();
|
||||
fastcgi_finish_request();
|
||||
|
||||
|
||||
//echo postSSLPage($url,json_encode($action));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user