Dr. Arne Jachens

Set up the Raspberry Pi

no warranty for any of the provided information

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);
}

?>

python

1HvcControl.py
2HvcHCSR04ultrasonic.py
3HvcMain.py
4HvcMotorDriver.py
5HvcOneWire.py
6HvcOperationMode.py
7HvcRaw2phys.py
8HvcReadSPI.py
9HvcSendI2C.py
10HvcSetGPIO.py
11HvcTables.py
12HvcWeather.py
13makeDoc.py

php

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

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