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_thermos200

Is used by:
HV_loop
HV_thermos200
index

Keine Erläuterungen gefunden.

<?php
/* published under GPL www.gnu.org/licenses/gpl.html */
include_once("HV_config.php");
include_once("HV_writeLog.php");
$pipeButton="./THERMOSBUTTONPRESS.fifo";
function HV_thermos200($what2do,$event,$vent){
  global $pipeButton;
  $pipeButton="./THERMOSBUTTONPRESS.fifo";
  $pipeData="./THERMOSDATA.fifo";
  $mode=0666;
  global $debug;
  if($debug){echo "<p><aj>HV_thermos200</aj> ".$what2do." ".$event."</p>\n";}
  static $vent;
  static $pIn;
  static $lastLevel;
  switch($what2do){
  case "vent":
    /* only if not manual mode */
    #if($vent['mode']>1){
      if($event==99){
	$lastLevel = $vent['level'];
	include("HV_ventProg.php");
	/* get actual vent level from table */
	$tmp=date('i');
	if($tmp>45){
	  $tmp=45;
	}elseif($tmp>30){
	  $tmp=30;
	}elseif($tmp>15){
	  $tmp=15;
	}else{
	  $tmp="00";
	}
	$time=date('H').":".$tmp;
	$vent['level'] = $level[$time];
      } #99
      /* set actual vent level */
      if($event==97 AND $lastLevel!=$vent['level']){
	if($vent['level']==1){
	  list($level,$mode) = writeButton("l","A");
	}elseif($vent['level']==2){
	  list($level,$mode) = writeButton("m","A");
	}elseif($vent['level']==3){
	  list($level,$mode) = writeButton("r","A");
	}
	$vent['level']=$level;
	$vent['mode'] =$mode;
      } #97
      if($event==95){
	#list($level,$mode) = checkVentStatus($pipeData); #haengt's hier?
	if($debug){echo "vent status set to: ".$level."\t ".$mode."\n";}
      } #95
    #} #some Auto mode
    break;
  case "Temp":
    /* enter menu */
    if($event==28){
      list($level,$mode) = writeButton("t","A");
    }
    /* menu up */
    if($event==24){
      $data = readVent($pipeData);
      list($level,$mode) = writeButton("m","A");
    }
    /* menu up */
    if($event==20){
      $data = readVent($pipeData);
      list($level,$mode) = writeButton("m","A");
    }
    /* enter Info */
    if($event==16){
      $data = readVent($pipeData);
      list($level,$mode) = writeButton("b","A");
    }
    /*read Data */
    if($event==12){
      $tmp = checkTempStatus($pipeData);
      if(!empty($tmp['Terde'])){
	$vent['Terde']=$tmp['Terde'];
	$vent['Tzulu']=$tmp['Tzulu'];
	$vent['Tablu']=$tmp['Tablu'];
	$vent['Tfolu']=$tmp['Tfolu'];
      }
      /* back to Menu */
      list($level,$mode) = writeButton("t","A");
    }
    /* back to ventilation */
    if($event==8){
      readVent($pipeData);
      list($level,$mode) = writeButton("t","A");
      $vent['level']=$level;
      $vent['mode'] =$mode;
    }
    if($event==4){
      $data = readVent($pipeData);
    }
    break;
  case "init":
    /* start thermos if not running yet */
    $cmd = "ps aux | grep thermos > foo";
    exec( $cmd);
    $pidThermos = `head -n 1 foo`;
    if(!strpos($pidThermos,"thermos200")>0){
      if($debug){echo "<p>delete old FIFOs</p>";}
      if(file_exists($pipeButton)){unlink($pipeButton);}
      if(file_exists($pipeData)){unlink($pipeData);}
      if($debug){echo "<p>old pipes deleted,<br>start thermos200</p>\n";}
      exec("./thermos200.x > /dev/null 2>/dev/null &");
      /* wait for ventilation to start up */
      $safe=0;
      while(!file_exists($pipeButton) AND $safe<100){
	if($debug){echo "<p>".$safe." startup ventilation, waiting...</p>\n";}
	$safe++;
	sleep(1);
      }
    }
    if(file_exists($pipeButton)){
      exec("chmod a+w ".$pipeButton);
    }else{
      echo "BUTTON.fifo was not created!\n";
    }
    #$success = posix_mkfifo ( $pipeButton, $mode ); #already opened by thermos200.x
    $success = posix_mkfifo ( $pipeData, $mode );
    if(file_exists($pipeData)){
      exec("chmod a+w ".$pipeData);
    }else{
      echo "DATA.fifo was not created!\n";
    }
    $vent['Terde']="";
    $vent['Tzulu']="";
    $vent['Tablu']="";
    $vent['Tfolu']="";
    $vent['level']="2";
    $vent['mode']="2";
    /* set ventilation to Auto, just in case */
    if($debug){
      echo "<p><aj>HV_thermos200_init:</aj> send 'a' to ".$pipeButton."</p>\n";
    }
    exec("echo \"A,A\" > vent.mode");
    list($level,$mode) = writeButton("i","i");
    sleep(4);
    list($level,$mode) = checkVentStatus($pipeData);
    break;
  default:
    /* button press */
    list($level,$mode) = writeButton($event,"m");
    if($mode<0){
      echo "<p>nothing after Temp in manual</p>";
      echo "<p>Press 'middle' to start ventilation!</p>\n";
      $result="";
    }else{
      include_once("HV_writeLog.php");
      $vent['today']=date('Y-m-d');
      $vent['now']  =date('H:i');
      $vent['level']=$level;
      $vent['mode'] =$mode;
      writeVent("write",$vent);
      /* read data stream */
      if(!file_exists($pipeData)){
	$success = posix_mkfifo ( $pipeData, $mode );
	exec("chmod a+w ".$pipeData);
      }
      sleep(1);
      #if($mode>0){
	$data = readVent($pipeData);
      #}else{
#	echo "<p>Press 'middle' to start ventilation!</p>\n";
 #     }
      if(strpos($data,"|")>0){
	$result = showData($data);
      }else{
	$result="";
      }
      $tmp = "<p>Level: ".$level."<br>Mode: ".$mode."</p>";
#array_push($result, $tmp);
    }
    return $result;
  }
  return $vent;
}

function writeButton($button,$operator){
  /* Any navigation of menu is only enabled if ventilation is in Auto mode.
  Since I operate the ventialtion levels via this script; i have to ensure 
  that the mode is first changed back to Auto before any other level or the 
  menu is choosen. Otherwise it might happen that there is no response by the 
  ventilation and the read pipe will lock!
  Therefore this state machine cares to always do appropriate operations by 
  the buttons.
   */
  global $debug;
  global $pipeButton;
  static $pOut;
  $pipeButton="./THERMOSBUTTONPRESS.fifo";
  if(!is_resource($pOut)){
    $pOut = fopen($pipeButton,"w+");
  }
  $lastLine  = `tail -n 1 vent.mode`;
  if(strlen($lastLine)>0){
    $tmp=explode(",",$lastLine);
    $ventMode = trim($tmp[0]);
    $lastOperator = trim($tmp[1]);
  }
  $lastVentMode=$ventMode;
  switch($ventMode){
  case "A":
    /* in Auto mode all buttons are valid */
    if($button=="l"){
      $ventMode="M1";
      $level=1;
      $mode=3;
    }else if($button=="m"){
      $ventMode="M2";
      $level=2;
      $mode=3;
    }else if($button=="r"){
      $ventMode="M3";
      $level=3;
      $mode=3;
    }else if($button=="t"){
      $ventMode="A0";
      $level=4;
      $mode=2;
    }else{
      $ventMode="A";
      $level=9;
      $mode=2;
    }
    break;
  case "A0":
    /* menu, first level */
    if($button=="b"){
      $ventMode="off";
      $level=0;
      $mode=3;
      break;
    }else{
      /* fall through */
    }
  case "A1":
    /* menu, first level */
    if($button=="t"){
      $ventMode="A";
      $level=2;
      $mode=2;
    }else if($button=="b"){
      $ventMode="A2";
      $level=5;
      $mode=2;
    }else{
      $ventMode="A1";
      $level=4;
      $mode=2;
    }
    break;
  case "A2":
    /* menu, second level */
    if($button=="t"){
      $ventMode="A1";
      $level=4;
      $mode=2;
    }else{
      $ventMode="A2";
      $level=5;
      $mode=2;
    }
    break;
  case "M1":
    if($button=="l"){
      $ventMode="A";
      $level=9;
      $mode=2;
    }else if($button=="m"){
      $ventMode="M2";
      $level=2;
      $mode=3;
    }else if($button=="r"){
      $ventMode="M3";
      $level=3;
      $mode=3;
    }else if($button=="t"){
      $ventMode="A1";
      $level=4;
      $mode=2;
      fwrite($pOut, "l");
      usleep(500000);
      #sleep(1);
    }else{
      $ventMode="M1";
      $level=1;
      $mode=3;
    }
    break;
  case "M2":
    if($button=="l"){
      $ventMode="M1";
      $level=1;
      $mode=3;
    }else if($button=="m"){
      $ventMode="A";
      $level=9;
      $mode=2;
    }else if($button=="r"){
      $ventMode="M3";
      $level=3;
      $mode=3;
    }else if($button=="t"){
      $ventMode="A1";
      $level=4;
      $mode=2;
      fwrite($pOut, "m");
      usleep(500000);
      #sleep(1);
    }else{
      $ventMode="M2";
      $level=2;
      $mode=3;
    }
    break;
  case "M3":
    if($button=="l"){
      $ventMode="M1";
      $level=1;
      $mode=3;
    }else if($button=="m"){
      $ventMode="M2";
      $level=2;
      $mode=3;
    }else if($button=="r"){
      $ventMode="A";
      $level=9;
      $mode=2;
    }else if($button=="t"){
      $ventMode="A1";
      $level=4;
      $mode=2;
      fwrite($pOut, "r");
      usleep(500000);
      #sleep(1);
    }else{
      $ventMode="M3";
      $level=3;
      $mode=3;
    }
    break;
  case "off":
    if($button=="m"){
      $ventMode="A";
      $level=2;
      $mode=2;
    }else{
      return array(0,0);
    }
    break;
  default:
    /* should not happen */
    $ventMode="undef";
    $level=9;
    $mode=9;
#    fwrite($pOut, "e");
    $button = "e";
  }

  if($lastOperator=="m" AND $operator=="A"){
    /* If caller is automatic mode, but we are in manual mode, do nothing*/
    /* do nothing */
    $tmp = date('Y-m-d').".butt";
    $f1=fopen($tmp,"a");
    $str = date('H:i:s')." | nothing \t".$ventMode." \t".$lastOperator." ".$operator."\n";
    fputs($f1,$str);
    fclose($f1);
    $level=-1;
    $mode=-1;
  }elseif($lastOperator=="A" 
	  AND ($ventMode=="A0" OR $ventMode=="A1" OR $ventMode=="A2") 
	  AND ($button=="u" OR $button=="p") ){
    // panel update not in menu navigation 
    $tmp = date('Y-m-d').".butt";
    $f1=fopen($tmp,"a");
    $str = date('H:i:s')." | buttonWhileTemp \t".$ventMode." \t".$lastOperator." ".$operator."\n";
    fputs($f1,$str);
    fclose($f1);
    $level=-1;
    $mode=-1;
  }else{
    /* write button to pipe */
    fwrite($pOut, $button);
    /* switch back to automatic mode */
    if($lastOperator=="m" AND $ventMode=="A" AND $button!="t"){$operator="A";}
    if(strlen($ventMode)<=3 AND $button!="p" AND $button!="u"){
      exec("echo \"".$ventMode.",".$operator."\" > vent.mode");
    }
    /* enable for debugging */
    $tmp = date('Y-m-d').".butt";
    $f1=fopen($tmp,"a");
    $str = date('H:i:s')." | ".$button."\t mode: ".$ventMode." \t lastOp: ".$lastOperator." Op:".$operator."\n";
    fputs($f1,$str);
    fclose($f1);
  }
  fclose($pOut);

  if($debug){
    echo "<p><aj>writeButton</aj> 
    state machine ".$lastVentMode." + ".$button." = ".$ventMode."</p>\n";
  }
  return array($level,$mode);
}

function readVent($pipeData){
  global $debug;
  if($debug){echo "<p><aj>readVent</aj> ".$pipeData."</p>\n";}
  if(file_exists($pipeData)){
    $pIn = fopen($pipeData,"r+");
    $data = "";
    $data = fread($pIn, 4096);
    fclose($pIn);
    $data=substr($data,0,strpos($data,"|EOM"));
    #echo $data;
    if($debug){echo "<p>data: ".$data."</p>\n";}
    return $data;
  }else{
    if($debug){echo "<p>file not found: ".$pipeData."</p>\n";}
    return "No reply of vent!";
  }
}


function showData($data){
  global $debug;
  if($debug){echo "<p><aj>showData</aj></p>\n";}
  $display=array();
  $message = explode("|",$data);
  $ll=-1;
  for ($l=0;$l<count($message);$l++){
    $thisLine=trim($message[$l]);
    $characters = explode(" ",$thisLine);
    if($characters[0]==138){
      $ll++;
      $display[$ll] = convertASCII($characters[0]);
      for($c=1;$c<count($characters);$c++){
	$display[$ll].= convertASCII($characters[$c]);
      } #c
      $display[$ll] = str_replace("norm al","normal",$display[$ll]);
      $display[$ll] = str_replace("m ax","max",$display[$ll]);
      $display[$ll] = str_replace("L  ftung","Lüftung",$display[$ll]);
      $display[$ll] = str_replace("Ger  t","Gerät",$display[$ll]);
      $display[$ll] = str_replace("Freig a ben","Freigaben",$display[$ll]);
      $display[$ll] = str_replace("N a cht a bsenkung","Nachtabsenkung",$display[$ll]);
      $display[$ll] = str_replace("Progr amme","Programme",$display[$ll]);
      $display[$ll] = str_replace("Temper aturen","Temperaturen",$display[$ll]);
      $display[$ll] = str_replace("Filterwe chsel","Filterwechsel",$display[$ll]);
    } #fi
  } #l
  if($debug){print_r($display);}
  return $display;
}


function checkVentStatus($pipeData){
  global $debug;
  if($debug){
    echo "<p><aj>HV_thermos200_checkVentStatus:</aj></p>\n";
  }
  $data = readVent($pipeData);
  $display = showData($data);
  $level=0;
  $mode=0;
  $dd=-1;
  for($d=0;$d<count($display);$d++){
    $tmp=str_replace(" ","",$display[$d]);
    $tmp="_".$tmp;
    if(strpos($tmp,"Autonormalmax")>0){
      $level=1;
      $mode=3;
    }elseif(strpos($tmp,"minAutomax")>0){
      $level=2;
      $mode=3;
    }elseif(strpos($tmp,"minnormalAuto")>0){
      $level=3;
      $mode=3;
    }elseif(strpos($tmp,"minnormalmax")>0){
      $mode=2;
      if(strpos($display[$d],"6")==5){
	if(strpos($tmp,"min"  )>0){$level=1;}
	if(strpos($tmp,"norm" )>0){$level=2;}
	if(strpos($tmp,"max"  )>0){$level=3;}
      }
    }elseif(strpos($tmp,">")>0 AND strpos($tmp,"<")>0){
      $mode=0;
    }
  } #d
  if($debug){
    echo "level: ".$level."<br>\n";
    echo "mode:  ".$mode."<br>\n";
  }
  return array($level,$mode);
}

function checkTempStatus($pipeData){
  global $debug;
  $data = readVent($pipeData);
  $display = showData($data);
  $dd=0;
  for($d=0;$d<count($display);$d++){
    if(strpos($display[$d],"Aussen")>0){
      $dd=$d;
      break;
    }
  } #d
  $result=array();
  if($dd>0){
    $result['Terde']=$display[$dd+1];
    $result['Tzulu']=$display[$dd+2];
    $result['Tablu']=$display[$dd+4];
    $keys = array_keys($result);
    for($r=0;$r<3;$r++){
      $tmp=$result[$keys[$r]];
      $tmp=substr($tmp,strpos($tmp,",")-4,7);
      $tmp=str_replace(",",".",$tmp);
      $result[$keys[$r]]=1.0*trim(str_replace(" ","",$tmp));
    }
    /* assume same mass flow and no condensation */
    $result['Tfolu']=$result['Tablu']-($result['Tzulu']-$result['Terde']);
    if($debug){
      echo "<p><aj>HV_thermos200_checkTempStatus:</aj></p>\n";
      $keys = array_keys($result);
      for($r=0;$r<4;$r++){
	echo $keys[$r].":\t ".$result[$keys[$r]]."<br>\n";
      }
    }
  }
  return $result;
}

include_once("HV_convertASCII.php");


function VentControlPanel(){
  include_once("HV_thermos200.php");
  #include_once("HV_setParameters.php");
  #HV_setParameters(0);
  if(isset($_POST['buttonPush'])){$buttonPush = $_POST['buttonPush'];}
  if(empty($buttonPush)){$buttonPush="p";}
  $buttonChar = $buttonPush[0];
  $display = HV_thermos200("default",$buttonChar,"");
  $displayText="";
  for($d=0;$d<min(100,count($display));$d++){
    if(strlen($display[$d])>5){
      $displayText.=$display[$d]."\n";
    }
  }
  $panel = "<form action='?what2do=menu' method='POST'>\n";
  $panel.="<table><tr><td><pre>".$displayText."</pre></td>
           <td><input type='submit' name='buttonPush' value='top'>   Menü ←<br><br><br><br>
           <input type='submit' name='buttonPush' value='bottom'>   ok →</td></tr>\n";
  $panel.="<tr><td align='center'><input type='submit' name='buttonPush' value='left'>
           <input type='submit' name='buttonPush' value='middle'>
           <input type='submit' name='buttonPush' value='right'>
<br>
min         normal         max<br>
    ↓            ↑            E/A<br>
→             -              +
           </td><td valign='top'>
          <!-- <input type='submit' name='buttonPush' value='update'> --></td></tr></table>\n";
  $panel.="</form>";
  #HV_writeConfig();
#
  return $panel;
}
?>
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!