Dr. Arne JachensDr. Arne Jachens

Heizungssteuerung Web-Interface

HV_showLog

This script utilizes Gnuplot to visualize the logfile data.

As 'default' a list of all existing logfiles is generated, to choose from. The intention of 'mode' is to provide specific diagrams depending on whether you want to analyze the solar or oven behaviour...
The respecting curves are plotted and as result the html image tag to the figure is returned. log file of solar heating control

<?php 
/* published under GPL www.gnu.org/licenses/gpl.html */
  /*
  $file="2013-08-24T00-00-01.log";
  $mode="solar";
  HV_showLog($file,$mode);
  */

function checkDataStructure($file){
  $delimiter = "\t";
  $date = substr($file,strpos($file,"_")+1);
  $path =substr($date,0,7)."/";
  $date = substr($date,0,10);
  $file = $path.$file;
  $cmd = "head -1 ".$file;
  exec($cmd,$output);
  $varNames = explode($delimiter,$output[0]);

  for($k=0;$k<count($varNames);$k++){
    $ColNo[$varNames[$k]]=$k+1;
  } #k
  
  $cmd = "tail -1 ".$file;
  exec($cmd,$output);
  $values = explode($delimiter,$output[1]);
  $time = $values[0];

  /*
  echo "<p>".$time." ".$path."</p>";
  print_r($ColNo);
  */
  return array($date,$time,$ColNo,$path);
}


function HV_showLog($timeStamp){
    $delimiter="\t";
    if(isset($_GET['mode'])){
        $mode=$_GET['mode'];
        $file=$_GET['file'];
    }else{
        $mode="default";
    }
    switch($mode){
    case "solar":
        list($date,$time,$ColNo,$path) = checkDataStructure($file);
        $fileS = $path.$file;
        $fileA = str_replace("sensors","actuators",$fileS);
        $fileW = $path."weather_".$date.".log";
        $plot = "set grid\n";
        $plot.= "set datafile missing \"-999.0\"\n";
        $plot.= "set term svg size 1200,400 \n";
        $plot.= "set output 'log.svg'\n";
        $plot.= "set key outside top right Left reverse\n";
        $plot.= "set xlabel 'time'\n";
        $plot.= "set ylabel 'Temperature [C]'\n";
        $plot.= "set yrange [0:110]\n";
        $plot.= "set y2label 'Power [kW]'\n";
        $plot.= "set y2range [0:7]\n";
        $plot.= "set xdata time\n";
        #$plot.= "set timefmt '%Y-%m-%dT%H:%M'\n";
        $plot.= "set timefmt '%H:%M'\n";
        $plot.= "set format x '%H:%M'\n";
        $plot.= "set y2tics\n";
        $plot.= "plot '".$fileW."' u 1:4              w lp lc rgb 'black' title 'T_{aussen}', \\\n";
        #    $plot.= "plot '".$fileW."' u 1:(2.5*$".$ColNo['sun']."*69.7/1000*($".$ColNo['flow']."-$".$ColNo['ret'].")) axis x1y2 w l lc rgb '#c0c0c0' title 'P_solar',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['flow']." w l lc rgb '#008000' title 'T_{Vorlauf}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['ret']."  w l lc rgb '#00ff00' title 'T_{Ruecklauf}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['TLow']." w l lc rgb 'orange' lw 3 title 'T_{Speicher unten}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['THot']." w l lc rgb 'red' lw 3 title 'T_{Seicher oben}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['coll']." w l lc rgb '#800080' lw 3 title 'T_{Kollektor}',\\\n";
        $plot.= " '".$fileA."' u 1:(100*$2)           w p lc rgb 'blue' ps 0.5 title 'A_{solar}'\n";
        #$plot.= "pause -1";
        $fd = fopen("log.gp","w");
        fputs($fd,$plot);
        fclose($fd);
        exec("gnuplot log.gp");
        #sleep(1);
        $result ="<p align='center'><img src='log.svg' alt='logfile'></p>";
        $result.="<p align='center'><a href='?what2do=showLog'>show Logfile</a></p>\n";
        return $result;
        break;
    case "heating":
        list($date,$time,$ColNo,$path) = checkDataStructure($file);
        $fileS = $path.$file;
        $fileA = str_replace("sensors","actuators",$fileS);
        $fileW = $path."weather_".$date.".log";
        $plot = "set grid\n";
        $plot.= "set datafile missing \"-999.0\"\n";
        $plot.= "set term svg size 1200,400 \n";
        $plot.= "set output 'log.svg'\n";
        $plot.= "set key outside top right Left reverse\n";
        $plot.= "set xlabel 'time'\n";
        $plot.= "set ylabel 'Temperature [C]'\n";
        $plot.= "set yrange [0:70]\n";
        $plot.= "set y2label 'Sonnenschein'\n";
        # $plot.= "set y2label 'Power [kW]'\n";
        $plot.= "set y2range [0:1]\n";
        $plot.= "set y2tics 0,0.5,1\n";
        $plot.= "set xdata time\n";
        $plot.= "set timefmt '%H:%M'\n";
        $plot.= "set format x '%H:%M'\n";
        # $plot.= "set y2tics\n";
        $plot.= "set style fill transparent solid 0.15 noborder\n";
        $plot.= "plot '".$fileW."' u 1:10  axis x1y2 w filledcurve fillcolor rgb '#ffee00' notitle, \\\n";
        $plot.= " '".$fileW."' u 1:10  axis x1y2 w l lc rgb 'yellow' title 'Sonnenschein', \\\n";
        $plot.= " '".$fileW."' u 1:4 w lp lc rgb 'black' title 'T_{aussen}', \\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['TLow']." w l lc rgb 'orange' lw 3 title 'T_{Speicher unten}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['THot']." w l lc rgb 'red' lw 3 title 'T_{Seicher oben}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['fire']." w l lc rgb '#008000' lw 3 title 'T_{Ofen}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['haus1']." w l lc rgb '#ff00ff' lw 3 title 'T_{Haus,WZ}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['haus2']." w l lc rgb '#ff00ff' lw 3 title 'T_{Haus,Maren}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['haus3']." w l lc rgb '#990099' lw 3 title 'T_{Haus,Arne}',\\\n";
        $plot.= " '".$fileA."' u 1:($4*10) w p lc rgb '#008080' pt 1 title 'A_{pump}',\\\n";
        $plot.= " '".$fileA."' u 1:($3*15) w p lc rgb 'blue' title 'A_{oven}'\n";
        #$plot.= "pause -1";
        $fd = fopen("log.gp","w");
        fputs($fd,$plot);
        fclose($fd);
        exec("gnuplot log.gp");
        #sleep(1);
        $result ="<p align='center'><img src='log.svg' alt='logfile'></p>";
        $result.="<p align='center'><a href='?what2do=showLog'>show Logfile</a></p>\n";
        return $result;
        break;
    case "ventilation":
        list($date,$time,$ColNo,$path) = checkDataStructure($file);
        $fileS = $path.$file;
        $fileA = str_replace("sensors","actuators",$fileS);
        $fileW = $path."weather_".$date.".log";
        $plot = "set grid\n";
        $plot.= "set datafile missing \"-999.0\"\n";
        $plot.= "set term svg size 1200,400 \n";
        $plot.= "set output 'log.svg'\n";
        $plot.= "set key outside top right Left reverse\n";
        $plot.= "set xlabel 'time'\n";
        $plot.= "set ylabel 'Temperature [C]'\n";
        # $plot.= "set y2label 'ventilation level'\n";
        $plot.= "set y2range [0:4]\n";
        #$plot.= "set key top left Left reverse\n";
        #   $plot.= "set boxwidth 1.0\n";
        $plot.= "set datafile missing '-999.0'\n";
        $plot.= "set y2tics ('off' 0, 'min' 0.27, 'normal' 0.6, 'max' 1) textcolor rgb '#008080'\n";
        $plot.= "set xdata time\n";
        $plot.= "set timefmt '%H:%M'\n";
        $plot.= "set format x '%H:%M'\n";
        $plot.= "plot '".$fileA."' u 1:($5) axis x1y2  w steps lw 2 lc rgb '#008080' title 'ventilation',\\\n";
        $plot.=" '".$fileW."' u 1:4 w lp lc rgb 'black' lw 3 title 'T_{aussen}', \\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['erde']." w l lc rgb '#0000ff' lw 3 title 'T_{Erde}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['zulu']."  w l lc rgb '#00ff00' lw 3 title 'T_{Zuluft}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['ablu']." w l lc rgb 'red' lw 3 title 'T_{Abluft}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['folu']." w l lc rgb 'cyan' lw 3 title 'T_{Fortluft}',\\\n";
        $plot.= " '".$fileS."' u 1:".$ColNo['walu']." w l lc rgb '#FBBF16' lw 3 title 'T_{Warmluft}',\\\n";
        $plot.= " '".$fileS."' u 1:($".$ColNo['posBp'].">1200?1:0) axis x1y2 w l lc rgb '#800000' lw 3 title 'Bypass'\n";
        $fd = fopen("log.gp","w");
        fputs($fd,$plot);
        fclose($fd);
        exec("gnuplot log.gp");
        #sleep(1);
        $result ="<p align='center'><img src='log.svg' alt='logfile'></p>";
        $result.="<p align='center'><a href='?what2do=showLog'>show Logfile</a></p>\n";
        return $result;
        break;
  case "H2O":
    include_once("HV_composeH2Oplot.php");
    $file = $_GET['file'];
    $month = substr($file,strpos($file,"_")+6,2);
    $msg = HV_composeH2Oplot($month);
    HV_H2Oplot($month);
    $result ="<p align='center'><img src='H2O.svg' alt='H2O level'></p>";
    $result.="<p align='center'><a href='?what2do=showLog'>show Logfile</a></p>\n";
    return $result;
    break;
  default:
    include_once("readFilenames.php");
  $year  = date('Y');
  $month = date('m');
  if(isset($_GET['month'])){$month=$_GET['month'];}
  $path = "./".$year."-".$month."/";
    $files = readFilenames($path,".txt");
    sort($files);
    $list ="<ul>\n";
    for($f=0;$f<count($files);$f++){
    if(strpos($files[$f],"ensor")>0)
      $list.="<li>".$files[$f]." <a href='?what2do=showLog&mode=solar&file=".$files[$f]."'>solar</a>   
                            <a href='?what2do=showLog&mode=heating&file=".$files[$f]."'>heating</a>  
                            <a href='?what2do=showLog&mode=ventilation&file=".$files[$f]."'>ventilation</a>
                            <a href='?what2do=showLog&mode=H2O&file=".$files[$f]."'>H2O</a></li>\n";
    } #f
    $list.="</ul>\n";
    return $list;
  } #switch

}
?>

Index of Library

1EM_editParameter.php
2EM_handleJSON.php
3EM_plot.php
4HV_Admin_Login.php
5HV_colorMap.php
6HV_composeH2Oplot.php
7HV_config.php
8HV_H2Olevel.php
9HV_readOperationState.php
10HV_restart.php
11HV_serviceLog.php
12HV_setParameters.php
13HV_showHouse.php
14HV_showLog.php
15HV_showWeatherForecast.php
16HV_TempCal.php
17index.php
18readFilenames.php
19readNamedData.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.