1Set up the Raspberry Pi
2Electrical Connection of Sensores and Actuators
3Set up the Connection
4Heating Control

no warranty for any of the provided information

HV_writeLog

Is used by:
HV_loop
HV_thermos200

Probably you will want to log the data of your home automation. This script collects data with a higher rate and writes it to file at slower rate.

  • init
    The logfile is initially opened, the string of date and time is used to have unique and meaningfull name for the logfiles.
  • collect
    The average is calculated for all incomming data.
  • write
    The mean values of the data are written to the logfile. And the mean values are reset to 0 for next interval.
  • final
    The logfile is closed. Use this with a following 'init' call to create a new logfile each day.
<?php 
/* published under GPL www.gnu.org/licenses/gpl.html */
function writeLog($data,$runState,$keys,$today,$now){
  static $fd;
  static $mean;
  static $callCounter;
  $result=TRUE;
  switch($runState){
  case "init":
    $now=str_replace(":","-",$now);
    $fname="".$today."T".$now.".log";
    $fd = fopen($fname,"w");
    $log ="#time";
    for($k=0;$k<count($keys);$k++){
      $log = sprintf("%s\t%s",$log,$keys[$k]);
      $mean[$k] = $data[$keys[$k]];
    } #k
    $callCounter=1;
    $log.="\n";
    fputs($fd,$log);
    break;
  case "final":
    fclose($fd);
    break;
  case "collect":
    $callCounter++;
    for($k=0;$k<count($keys);$k++){
      $mean[$k]=$mean[$k]+$data[$keys[$k]];
    } #k
    break;
  case "write":
    $time=$today."T".$now;
    $log = sprintf("%s",$time);
    for($k=0;$k<count($keys);$k++){
      $mean[$k] = $mean[$k]/($callCounter);
      $log = sprintf("%s\t%f",$log,$mean[$k]);
      $mean[$k] = 0;
    } #k
    $log.="\n";
    fputs($fd,$log);
    $callCounter=0;
    break;
  default:
    $result=FALSE;
  } #switch
  return $result;
}

function writeVent($runState,$vent){
  static $fd;
  $result=TRUE;
  $keys=array_keys($vent);
  switch($runState){
  case "init":
    $now=str_replace(":","-",$vent['now']);
    $fname="".$vent['today']."T".$now.".vent";
    $fd = fopen($fname,"w");
    $log = "#dateTime";
    for($k=0;$k<count($keys);$k++){
      if($keys[$k]!="today" AND $keys[$k]!="now"){
	$log = sprintf("%s\t%s",$log,$keys[$k]);
      }
    } #k
    $log.="\n";
    fputs($fd,$log);
    break;
  case "final":
    fclose($fd);
    break;
  case "write":
    /* wenn control panel ausfuehrt, ist fd nicht bekannt, daher einfach letzte datei oeffnen? */
    if(empty($fd)){
      include_once("readFilenames.php");
      $files = readFilenames("./","\.vent");
      sort($files);
      $file = $files[count($files)-1];
      #$file = escapeshellarg($file);
      $fd = fopen($file,"a");
      $firstLine = `head -n 1 $file`;
      $lastLine  = `tail -n 1 $file`;
      $myKeys=explode("\t",$firstLine);  
      $values = explode("\t", $lastLine);
      $myVent = $vent;
      for ($k=1;$k<count($myKeys);$k++){
	$keys[$k-1]=trim($myKeys[$k]);
	$vent[$keys[$k-1]]=sprintf("%4.1f",$values[$k]);
      } #k
      $myKeys = array_keys($myVent);
      for ($k=0;$k<count($myKeys);$k++){
	$vent[$myKeys[$k]] = $myVent[$myKeys[$k]];
      } #k
    } #fi
    $time=$vent['today']."T".$vent['now'];
    $log = sprintf("%s",$time);
    for($k=0;$k<count($keys);$k++){
      if($keys[$k]!="today" AND $keys[$k]!="now")
	$log = sprintf("%s\t%f",$log,$vent[$keys[$k]]);
    } #k
    $log.="\n";
    fputs($fd,$log);
    break;
  default:
    $result=FALSE;
  } #switch
  return $result;
}
?>
1HV_Admin_Login
2HV_colorMap
3HV_config
4HV_convertASCII
5HV_getSunPrediction
6HV_heatingControl
7HV_loop
8HV_readOperationState
9HV_readTemperatures
10HV_restart
11HV_serviceLog
12HV_setActuators
13HV_setParameters
14HV_showHouse
15HV_showLog
16HV_showRawValues
17HV_showWeatherForecast
18HV_thermos200
19HV_ventProg
20HV_writeLog
21index
22MoistAir
23readFilenames
24readNamedData
25tableInterpol

 

gnuplot

gnuplot is used to visualise the results - via script you can do infinite diagrams in 1 second.
Run 'test' in gnuplot to get an owerview of the available line- and symbolstyles.

Login
Valid HTML 4.01!