Heating and Ventilation Control
/HV_Fronius
Keine Erläuterungen gefunden.
<?php function HV_Fronius() { $html = ""; if( isset($_GET["mode"]) ){ $what2do = $_GET["mode"]; }else{ $what2do = "day"; } if( isset($_GET["date"]) ){ $date = $_GET["date"]; }elseif( isset($_POST["date"]) ){ $date = $_POST["date"]; }else{ $date = 0; } #fi date get $message = "<p><aj>HV_Fronius</aj>(w2d: ".$what2do.", date: ".$date.")<br>\n"; #echo $message; switch($what2do){ case "status": $html.= HV_FroniusStatus(); break; case "injection": $html.= HV_FroniusInjection( $date ); break; case "day": default: $html.= HV_FroniusDayly( $date ); } $html.= "<form method='POST' action='?what2do=solar&mode=injection'>\n"; $html.= "<label for='date'>Monat</label>\n"; $html.= "<select id='date' type='select' name='date'>\n"; $html.= "<option value='01'>Januar</option>\n"; $html.= "<option value='02'>Februar</option>\n"; $html.= "<option value='03'>März</option>\n"; $html.= "<option value='04'>April</option>\n"; $html.= "<option value='05'>Mai</option>\n"; $html.= "<option value='06'>Juni</option>\n"; $html.= "<option value='07'>Juli</option>\n"; $html.= "<option value='08'>August</option>\n"; $html.= "<option value='09'>September</option>\n"; $html.= "<option value='10'>Oktober</option>\n"; $html.= "<option value='11'>November</option>\n"; $html.= "<option value='12'>Dezember</option>\n"; $html.= "</select>\n"; $html.= "<button type='submit' name='mode' value='Monthly'>Berechne</button>\n"; $html.= "</form>\n"; $html.= "<p><a href='?what2do=solar&mode=status'>Wechselrichter Status</a></p>\n"; return $html; } function HV_FroniusStatus() { $html = ""; $fname = "HVC/FroniusStatus.html"; if (file_exists($fname)) { $fid = fopen($fname, "r"); $line = fgets( $fid, 1024 ); while(!feof($fid)){ $html.=$line; $line = fgets( $fid, 2048 ); } fclose($fid); }else{ printf("FILE ".$fname." DOES NOT EXIST!\n"); } return $html; } function HV_FroniusDayly($date){ $date = $_GET["date"]; $month = substr($date, 0, 7); // Correcting the substr to get the month properly (YYYY-MM) $dataFile = "HVC/LogDir/" . $month . "/power_" . $date . ".dat"; // Gnuplot script preparation $plot = "set grid\n"; $plot .= "set key top left\n"; $plot .= "set xdata time\n"; $plot .= "set timefmt '%H:%M'\n"; $plot .= "set format x '%H:%M'\n"; $plot .= "set datafile missing 'None'\n"; $plot .= "set yrange [0:]\n"; $plot .= "set title '" . $date . "'\n"; $plot .= "set ylabel 'Leistung [W]'\n"; $plot .= "set term svg\n"; $plot .= "set output 'fronius.svg'\n"; $plot .= "plot '" . $dataFile . "' using 1:(-1*\$2) with filledcurve y1=0 lc rgb '#ff0066' fs solid 0.5 notitle, \\\n"; $plot .= " '" . $dataFile . "' using 1:(-1*\$2) w l lc rgb '#ff0066' title 'Verbrauch', \\\n"; $plot .= " '" . $dataFile . "' using 1:(-1*\$2):4 with filledcurve y1=2 lc rgb '#008000' fs solid 0.5 notitle, \\\n"; $plot .= " '" . $dataFile . "' using 1:4 w l lc rgb '#008000' title 'Ertrag'\n"; // Write Gnuplot script to file $pid = fopen("fron.gp", "w"); if ($pid === false) { return "<p>Error: Unable to open fron.gp for writing.</p>"; } fputs($pid, $plot); fclose($pid); // Execute Gnuplot command $cmd = "/usr/bin/gnuplot fron.gp"; exec($cmd, $output, $retVal); // Return result based on Gnuplot execution if ($retVal) { $html = "<p>Gnuplot error, return value: " . $retVal . "</p>"; } else { $html = "<p><img src='fronius.svg?rand=" . rand(0, 99) . "'></p>\n"; } return $html; } function HV_FroniusInjection( $date, $delimiter="\t" ){ $month = date('m'); $year = date('Y'); if( $date > $month ){ $year = $year-1; } $path = "./HVC/LogDir/".$year."-".$month."/"; $message = "<p><aj>HV_FroniusInjection</aj>(".$year."-".$month.")<br>"; $fileNames=array(); if( is_dir($path) ){ if ($dh = opendir($path)) { while (($file = readdir($dh)) !== false) { if( !is_dir($path."/".$file) ){ if( strpos($file, "ower")>0 ){ array_push($fileNames,$file); } } } #while closedir($dh); } } $message.= "in path: ".$path."<br>"; $message.= "found: ".print_r($fileNames,TRUE)."<br>"; $EsolarTot = []; $EhouseTot = []; $EinjectTot = []; foreach( $fileNames as $file ){ $fname = $path."/".$file; $Esolar = 0; $Ehouse = 0; $Einject = 0; $fid = fopen($fname, "r"); $line = fgets( $fid, 2048 ); #headerline $line = fgets( $fid, 2048 ); $n=0; while(!feof($fid)){ $n++; $values = explode($delimiter,$line); if( !is_numeric( trim($values[1]) ) ){ echo $fname."<br>"; echo $n.": ".$line."<br>"; print_r($values); exit(); } $Ehouse = $Ehouse - $values[1]; $values[3] = trim($values[3]); if( is_numeric( $values[3] )){ $Esolar = $Esolar + $values[3]; if( $values[3]>-$values[1] ){ $Einject = $Einject +( $values[3] + $values[1] ); } }else{ #echo $values[3]." is not numeric<br>"; } $line = fgets( $fid, 2048 ); } #while # rescale: *5min / 60s/min * 1h/3600s array_push($EsolarTot, 0.001*0.8333 * $Esolar); array_push($EinjectTot, 0.001*0.8333 * $Einject); array_push($EhouseTot, 0.001*0.8333 * $Ehouse); } #foreach $fid = fopen("monthly.dat","w"); $sumSol=0; $sumHouse=0; $sumInj =0; for( $i=0; $i<count($EsolarTot);$i++ ){ $string = $i."\t".$EhouseTot[$i]."\t".$EinjectTot[$i]."\t".$EsolarTot[$i]."\n"; fputs($fid, $string); $sumSol = $sumSol + $EsolarTot[$i]; $sumHouse = $sumHouse + $EhouseTot[$i]; $sumInj = $sumInj + $EinjectTot[$i]; } #i fclose($fid); // Gnuplot script preparation $dataFile = "monthly.dat"; $plot = "set grid\n"; $plot .= "set key top left\n"; $plot .= "set yrange [0:]\n"; $plot .= "set title '" . $year."-".$month . "'\n"; $plot .= "set ylabel 'Energie [kWh]'\n"; $plot .= "set term svg\n"; $plot .= "set output 'monthly.svg'\n"; $plot .= "plot '" . $dataFile . "' using 1:(\$2) with filledcurve y1=0 lc rgb '#ff0066' fs solid 0.5 notitle, \\\n"; $plot .= " '" . $dataFile . "' using 1:(\$2) w l lc rgb '#ff0066' title 'Verbrauch', \\\n"; $plot .= " '" . $dataFile . "' using 1:(\$2):4 with filledcurve y1=2 lc rgb '#008000' fs solid 0.5 notitle, \\\n"; $plot .= " '" . $dataFile . "' using 1:4 w l lc rgb '#008000' title 'Ertrag'\n"; // Write Gnuplot script to file $pid = fopen("monthly.gp", "w"); fputs($pid, $plot); fclose($pid); // Execute Gnuplot command $cmd = "/usr/bin/gnuplot monthly.gp"; exec($cmd, $output, $retVal); $html = "<h2>Energieertrag</h2>\n"; $html.="<table>\n"; $html.="<tr><td>Ertrag: </td><td>".sprintf("%4.1f",$sumSol)." kWh</td></tr>\n"; $html.="<tr><td>Verbrauch: </td><td>".sprintf("%4.1f",$sumHouse)." kWh</td></tr>\n"; $html.="<tr><td>Einspeisung: </td><td>".sprintf("%4.1f",$sumInj)." kWh</td></tr>\n"; $html.="</table>\n"; // Return result based on Gnuplot execution if ($retVal) { $html.= "<p>Gnuplot error, return value: " . $retVal . "</p>"; } else { $html.= "<p><img src='monthly.svg?rand=" . rand(0, 99) . "'></p>\n"; } return $html; } /* TESTING echo HV_FroniusInjection( "08" ); */ ?>
python
php
Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.