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_getSunPrediction

Is used by:
HV_getSunPrediction
HV_loop

To decide whether the combustion heating should be operated in the morning or wait until the sun rises I plan to relay the control on some local weather prediction.

To gain the weather prediction I had a look to local weather forecastes and created a cron job which pulls the forecast
sudo nano /etc/cron.hourly/getSunPrediction
looks like

#!/bin/sh
cd /var/www/ && /bin/rm -f oldWeatherFile && /usr/bin/wget http://www.weather-foreca.st/local
sudo chmod a+x /etc/cron.hourly/getSunPrediction
and to run this four times each day I modified
sudo nano /etc/crontab
the hourly line to
55 5,11,17,23 * * *     root    cd / && run-parts --report /etc/cron.hourly

The following script HV_getSunPrediction which parses the pulled web page is executed shortly after the last pull by HV_loop and returns the indicated values for temperature, humidity, pressure and sun shine probability.

These values are handed to the second function HV_look4weather which

  • calculates the specific humidity
    I assume this more appropriate to determine the risk of condensation in my earth heating register of my ventilation intake later on...
  • stores the values to a dayly logging file for later purpose.

<?php
  /* 
1) Find a weather forcast for your region, with a sun prediction (in %)
2) Try to pull the page using wget
3) Set up a dayly cron job
sudo nano /etc/crontab
55 5,11,17,23   * * *   root    cd / && run-parts --report /etc/cron.hourly

   sudo nano /etc/cron.hourly/getSunPrediction 
#!/bin/sh

cd /var/www/ && /bin/rm -f de_63674_altenstadt && /usr/bin/wget http://www.wetter.de/de_63674_altenstadt && /bin/chmod a+rw /var/www/de_63674_altenstadt
sudo chmod a+x /etc/cron.hourly/getSunPrediction 
4) read and parse file...

   HV_getSunPrediction("de_63674_altenstadt");
   */
function HV_getSunPrediction($fname){
  /* read weather from wget */
  if (file_exists($fname)) {
    $sf = fopen($fname, "r");
    $line = fgets( $sf, 2048 );
    $weather = $line;
    while(!feof($sf)){
      $line = fgets( $sf, 2048 );
      $weather.= $line;
    }
    fclose($sf);
  }else{
    printf("FILE ".$fname." DOES NOT EXIST!\N");
  }
  /* find currentweather */
  $weather=substr($weather,strpos($weather,"currentweather"));
  /* Temperature for humidity */
  $weather=substr($weather,strpos($weather,"C")-6);
  $weather=substr($weather,strpos($weather,"<b>")+3);
  $TempHumStr=substr($weather,0,3);
  $TempHumStr=substr($TempHumStr,0,strpos($TempHumStr,"")-1);
  $TempHum=trim($TempHumStr);

  /* find sun prediction */
  $weather=substr($weather,strpos($weather,"Relative Feuchte"));
  $weather=substr($weather,strpos($weather,"<b>")+3);
  $humidityStr=substr($weather,0,3);
  $humidity=trim($humidityStr);
  /* find pressure */
  $weather=substr($weather,strpos($weather,"Luftdruck"));
  $weather=substr($weather,strpos($weather,"<b>")+3);
  $pressureStr=substr($weather,0,4);
  $pressure=trim($pressureStr)*100;
  /*find sun prediction */
  $weather=substr($weather,strpos($weather,"Sonnenschein"));
  $weather=substr($weather,strpos($weather,"<b>")+3);
  $sunshineStr=substr($weather,0,3);
  $sunshine=trim($sunshineStr);

#  echo $TempHum." Temp ".$humidity." hum ".$sunshine." sun\n";
  #$pressure=101.325;
  return array($sunshine,$TempHum,$humidity,$pressure);
}

/*
$sens=HV_look4weather("00:01");
print_r($sens);
*/

function HV_look4weather($today,$now){
  include_once("MoistAir.php");
  include_once("HV_getSunPrediction.php");
  list($Sens["sunshine"],$Sens["Tambient"],$relHumidity,$Sens["pressure"]) = HV_getSunPrediction("de_63674_altenstadt");
  $rhoAir = densityAir(273+$Sens["Tambient"],$Sens["pressure"]);
  $rhoW = absHumidity2(273+$Sens["Tambient"],$relHumidity/100);
  $Sens["specHumidity"] = specHumidity($rhoW,$rhoAir);
  $sf=fopen("ambient".$today.".tsv","a");
  $ambient=sprintf("%s%s%s\t",$today,"T",$now);
  $ambient=sprintf("%s%4.3f\t",$ambient,$Sens["Tambient"]);
  $ambient=sprintf("%s%4.3e\t",$ambient,$Sens["specHumidity"]);
  $ambient=sprintf("%s%4.3f\t",$ambient,$Sens["sunshine"]);
  $ambient=sprintf("%s%4.3e\n",$ambient,$Sens["pressure"]);
  fputs($sf,$ambient);
  fclose($sf);
  return $Sens;
}
?>
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!