Dr. Arne Jachens

Set up the Raspberry Pi

no warranty for any of the provided information

HV_showWeatherForecast

Just to indicate that the pulling of the weather forecast works, this fuctions reads the last line of the weather logfile and shows its values.

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


include_once("HV_config.php");


function HV_showWeatherForecast($weather){
  $today = date('Y-m-d');
  mergeWeatherForecasts($today);


  $plot ="set term png size 800,300\n";
  $plot.="set output 'weather.png'\n";
  $plot.="set grid\n";
  $plot.="set key outside\n";
  $plot.="set xdata time\n";
  $plot.="set timefmt '%Y-%m-%dT%H'\n";
  $plot.="set format x '%H'\n";
  $plot.="set y2tics ('0' 0, '10' 0.1, '20' 0.2, '30' 0.3, '40' 0.4, '50' 0.5, '60' 0.6, '70' 0.7, '80' 0.8, '90' 0.9, '100' 1) textcolor rgb 'blue'\n";
  $plot.="set yrange [-10:30]\n";
  $plot.="set y2range [0:1]\n";
  $plot.="set style line 2 lt 1 lc rgb '#ff0000' lw 1 pt 7 ps 1\n";
  $plot.="set style line 3 lt 1 lc rgb '#00ffff' lw 1 pt 7 ps 1\n";
  $plot.="set style line 4 lt 1 lc rgb '#fbbf16' lw 1 pt 7 ps 1\n";
  $plot.="set style line 5 lt 1 lc rgb '#8b008b' lw 1 pt 7 ps 1\n";
  $plot.="set style line 6 lt 1 lc rgb '#8b008b' lw 1 pt 7 ps 1\n";
  $plot.="set style line 7 lt 1 lc rgb '#0000ff' lw 1 pt 7 ps 1\n";
  $plot.="set style line 8 lt 1 lc rgb '#ff00ff' lw 1 pt 7 ps 1\n";
  $pointintime = date('Y-m-d')."T".date('H');
  $plot.=" #set arrow from '2018-10-13T23',1 to '2018-10-13T23',40 nohead lc rgb 'green'\n";
  $plot.="set arrow from '".$pointintime."',second 0 to '".$pointintime."',second 1 nohead lw 2 lc rgb 'green'\n";
  $plot.="plot 'weather.dat' u 1:4 ls 2 w lp ti 'Temperatur [C]',\\\n";
  $plot.="'weather.dat' u 1:($12) axes x1y1 ls 3 w lp ti 'Feuchte [g/kg]',\\\n";
  $plot.="'weather.dat' u 1:10 axes x1y2 ls 4 w lp ti 'Sonne [%]',\\\n";
  $plot.="'weather.dat' u 1:($7/100) axes x1y2 ls 6 w lp ti 'Feuchte [%]',\\\n";
  $plot.="'weather.dat' u 1:(10*$8) axes x1y1 ls 7 w l ti 'Niederschlag [0.1 mm/m2]',\\\n";
  $plot.="'weather.dat' u 1:(3.6*$11/100) axes x1y2 ls 8 w l ti 'Wind [0.01 km/h]'\n";
  #$plot.="#pause -1\n";
  #$plot.="replot\n";
  $pid = fopen("weather.gp","w");
  fputs($pid,$plot);
  fclose($pid);

  $cmd = "gnuplot weather.gp";
  exec($cmd);

  $weatherLogToday = date('Y-m')."/weather_".date('Y-m-d').".log";
  if (file_exists($weatherLogToday)) {
      $updateTime=date("d F Y H:i:s.", filectime($weatherLogToday));
  }else{
      $updateTime="00:99";
  }
  
  $weatherString ="\n<p style='color:teal;'>Wettervorhersage von ".$updateTime." Uhr\n";
  $weatherString.="<table><tr><td>\n";
  $weatherString.="<table>\n";
  $weatherString.="<tr><td style='color:teal;'>Temperatur:   </td>
                         <td style='color:teal;'>".sprintf("%3.1f ",$weather['TAmb'])." °C </td></tr>\n";
  $weatherString.="<tr><td style='color:teal;'>spez. Feuchte:</td>
                         <td style='color:teal;'>".sprintf("%3.1f ",$weather['x'])."   </td></tr>\n";
  $weatherString.="<tr><td style='color:teal;'>Sonnenschein: </td>
                         <td style='color:teal;'>".sprintf("%3.1f ",$weather['sun'])."%   </td></tr>\n";
  $weatherString.="<tr><td style='color:teal;'>Luftdruck:    </td>
                         <td style='color:teal;'>".sprintf("%3.1f ",$weather['p'])." kPa  </td></tr>\n";
  $weatherString.="<tr><td style='color:teal;'>rel. Feuchte:    </td>
                         <td style='color:teal;'>".sprintf("%3.1f ",$weather['phi'])." %  </td></tr>\n";
  $weatherString.="<tr><td style='color:teal;'>Niederschlag:    </td>
                         <td style='color:teal;'>".sprintf("%3.1f ",$weather['rain'])." mm/m2  </td></tr>\n";
  $weatherString.="<tr><td style='color:teal;'>max. Wind:    </td>
                         <td style='color:teal;'>".sprintf("%3.1f ",$weather['windMax'])." m/s  </td></tr>\n";
  $weatherString.="</table>\n";
  $weatherString.="</td><td>\n";
  $weatherString.="<img src='weather.png' alt='aktuelles Wetter'>";
  $weatherString.="</td></tr></table>\n";
  return $weatherString;
}



function HV_actualWeather($date,$hour,$minutes){
    global $debug;
    if($debug){echo "<p><aj>HV_actualWeather</aj>: ".$date." ".$hour." ".$minutes."</p>";}
    /* read weather */
    $month = substr($date,0,7);
    $file=$month."/"."weather_".$date.".log";
    $weatherStr=array();
    if (file_exists($file)) {
        $sf=fopen($file,"r");
        for($t=0;$t<=24;$t++){
            $weatherStr[$t] = trim(fgets($sf,2048));
        } #t
        fclose($sf);
    }else{
        echo "<p>FILE ".$file." NOR FOUND</p>";
        $weather=array();
        $myTime=array();
    } #fi

    #find the relevant lines and interpolate to the minute
    $varNames = explode("\t",$weatherStr[0]);
    for($v=0;$v<count($varNames);$v++){
        $colNo[$varNames[$v]] = $v;
    } #v
    
    $actWeather = array();
    for($t=1;$t<count($weatherStr);$t++){
        $weather = explode("\t",$weatherStr[$t]);
        $thisHour = substr($weather[$colNo['#time']],0,2);
        if($t==23){
            for($v=1;$v<count($varNames);$v++){
                $actWeather[$varNames[$v]] = $weather[$colNo[$varNames[$v]]];
            }
        }elseif(1*$thisHour > $hour){
            $w = $minutes/60.0;
            for($v=1;$v<count($varNames);$v++){
                $Tnext = $weather[$colNo[$varNames[$v]]];
                $Tlast = $weatherLast[$colNo[$varNames[$v]]];	
                $actWeather[$varNames[$v]] = (1.0-$w)*$Tlast + $w*$Tnext;
            } #v
            break;
        } #fi
        $weatherLast = $weather;
    } #t
    if($debug){print_r($actWeather);}

    return $actWeather;
}


function mergeWeatherForecasts($today){
    global $debug;
    if($debug){echo "<p><aj>mergeWeatherForecasts</aj>:</p>";}
    $month = substr($today,0,7);
    $wf[0] = $month."/weather_".$today.".log";
    $nday[0] = $today;
    for($d=1; $d<3; $d++){
        $nday[$d] = date('Y-m-d', strtotime($today .' +'.$d.' day'));
        $month = substr($nday[$d],0,7);		  
        $wf[$d] = $month."/weather_".$nday[$d].".log";
    } #d
  
    $allWeather = array();
    $t=-1;
    for($d=0; $d<count($wf); $d++){
        $handle = fopen($wf[$d], "r");
        if ($handle) {
            while (($buffer = fgets($handle, 4096)) !== false) {
                if($buffer[0]!=" #"){
                    $t++;
                    $allWeather[$t] = $nday[$d]."T".$buffer;
                }
            } #fi
            fclose($handle);
        } #fi
    } #d

    $fid = fopen("weather.dat","w");
    for($t=0;$t<count($allWeather);$t++){
        fputs($fid,$allWeather[$t]);
    } #t
    fclose($fid);

    if($debug){
        print_r($wf);
        echo "<p>wrote weather.dat</p>";
    }
}
  

?>

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.