Hamburger Hamburger

Heizungssteuerung Web-Interface

HV_readOperationState

Read in the last line of the logfile as input for visualization. Instead of reading the hole file, the command line functions head and tail are used.

The parameter $NoSensors indicates the position where sensor values end and actuator values start.

<?php 
/* published under GPL www.gnu.org/licenses/gpl.html */

function HV_readOperationState($opModFile){
    include_once("readFilenames.php");
    global $debug;
    $year  = date('Y');
    $month = date('m');
    if(isset($_GET['month'])){$month=$_GET['month'];}
    $path = "./".$year."-".$month."/";
  
    if($debug){echo "<p><aj>HV_readOperationState</aj>: ".$year." ".$month." ".$path."</p>";}

    /* read logfile */
    $files = readFilenames($path,".txt");
    sort($files);
    $file = $files[count($files)-1];
    $date=substr( $file, strpos($file,"_") );
    $actFile  = $path."actuatorsLog".$date;
    $sensFile = $path."sensorsLog".$date;
    list($sensors,$timeStamp)   = lastData($sensFile);
    list($actuators,$timeStamp) = lastData($actFile);


    $operationMode = readOperationMode($opModFile);

    if($debug){
        echo "<p><aj>HV_readOperationState( )</aj></p>\n";
        print_r($sensors); echo "<br>";
        print_r($actuators); echo "<br>";
        print_r($operationMode); echo "<br>";
    }

    return array($timeStamp,$sensors,$actuators,$operationMode);
}

function readOperationMode($opModFile){
    global $debug;
  $fid = fopen($opModFile,"r");
  $opModStr = trim(fgets($fid,2048));  
  fclose($fid);
  $opModStr = substr($opModStr,1);
  $opModStr = substr($opModStr,0,strlen($opModStr)-2);
  $opModStr = str_replace("\"","",$opModStr);
  $tmp = explode(",",$opModStr);
  for($m=0;$m<count($tmp);$m++){
    $thisM = explode(":",$tmp[$m]);
    $operationMode[trim($thisM[0])] = trim($thisM[1]);
  } #m
  
    if($debug){
        echo "<p><aj>HV_readOperationMode( )</aj></p>\n";
    }
    
  return $operationMode;
}



function lastData($file){
    global $debug;
    
    if (file_exists($file)){
        /* get first line of logfile for  varNames */
        $cmd = "head -1 ".$file;
        exec($cmd,$output);
        if($debug){echo $cmd."<br>";}
        
        $varNames = explode("\t",$output[0]);
        #for($v=0;$v<count($varNames);$v++){
        #    $ColNo[$varNames[$v]] = $v;
        #} #v
    
        /* get last line of data */
        $cmd = "tail -1 ".$file;
        exec($cmd,$output);
        if($debug){echo $cmd."<br>";}
        
        $values = explode("\t",$output[1]);
        for($v=1;$v<count($varNames);$v++){
            $data[$varNames[$v]] = $values[$v];
        } #v
    
        /* timeStamp of logfile */
        $timeStamp = $values[0];
    } else {
        echo "<p>FILE ".$file." NOT FOUND</p>";
    } #fi 

    return array($data,$timeStamp);
}

?>

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.