…und hier stehen die Anleitungen, um die Davis-Wetterstation in Betrieb zu nehmen. Mit diesem Material lässt sich die Station betreiben ohne auf irgendwelche Umwege zu gehen. Insbesondere ist es nicht nötig, die furchtbare Auswerte-Software von Davis zu bemühen. Und auch die komische Software für 30 EUR braucht es dann auch nicht!
Zunächst der Loop-Trigger. Dieser Script sendet den „LOOP“-Befehl an die serielle Schnittstelle, und sollte immer wieder (bei mir: alle 15 Minuten) laufen:
<?
$crlf = chr(0x0D).chr(0x0A);
$cr = chr(0x0D);
$lf = chr(0x0A);
ComPort_SetDTR(44862 /*[SerialPortWetterstation]*/, true);
/*
COMPORT_SendText(44862 /*[SerialPortWetterstation]*/,"RXCHECK".$lf);
IPS_Sleep(300);
COMPORT_SendText(44862 /*[SerialPortWetterstation]*/,"RXCHECK".$lf);
IPS_Sleep(300);
*/
COMPORT_SendText(44862 /*[SerialPortWetterstation]*/,$lf);
IPS_Sleep(300);
COMPORT_SendText(44862 /*[SerialPortWetterstation]*/,$lf);
IPS_Sleep(300);
COMPORT_SendText(44862 /*[SerialPortWetterstation]*/,"LOOP 1".$lf);
?>
Dann meldet sich die serielle Schnittstelle mit einem Wortschwall, welcher vom folgenden Script in seine Einzelteile zerlegt wird:
<?php
$crlf = chr(0x0D).chr(0x0A);
$cr = chr(0x0D);
$lf = chr(0x0A);
// The WeatherLoopData class extracts and stores the weather data from the array of bytes returned from the Vantage weather station
// The array is generated from the return of the LOOP command.
//
// Contents of the character array (LOOP packet from Vantage):
//
// Field Offset Size Explanation
// "L" 0 1
// "O" 1 1
// "O" 2 1 Spells out "LOO" for Rev B packets and "LOOP" for Rev A packets. Identifies a LOOP packet
// "P" (Rev A), Bar Trend (Rev B) 3 1 Signed byte that indicates the current 3-hour barometer trend. It is one of these values:
// -60 = Falling Rapidly = 196 (as an unsigned byte)
// -20 = Falling Slowly = 236 (as an unsigned byte)
// 0 = Steady
// 20 = Rising Slowly
// 60 = Rising Rapidly
// 80 = ASCII "P" = Rev A firmware, no trend info is available.
// Any other value means that the Vantage does not have the 3 hours of bar data needed
// to determine the bar trend.
// Packet Type 4 1 Has the value zero. In the future we may define new LOOP packet formats and assign a different
// value to this field.
// Next Record 5 2 Location in the archive memory where the next data packet will be written. This can be
// monitored to detect when a new record is created.
// Barometer 7 2 Current Barometer. Units are (in Hg / 1000). The barometric value should be between 20 inches
// and 32.5 inches in Vantage Pro and between 20 inches and 32.5 inches in both Vantatge Pro
// Vantage Pro2. Values outside these ranges will not be logged.
// Inside Temperature 9 2 The value is sent as 10th of a degree in F. For example, 795 is returned for 79.5?F.
// Inside Humidity 11 1 This is the relative humidity in %, such as 50 is returned for 50%.
// Outside Temperature 12 2 The value is sent as 10th of a degree in F. For example, 795 is returned for 79.5?F.
// Wind Speed 14 1 It is a byte unsigned value in mph. If the wind speed is dashed because it lost synchronization
// with the radio or due to some other reason, the wind speed is forced to be 0.
// 10 Min Avg Wind Speed 15 1 It is a byte unsigned value in mph.
// Wind Direction 16 2 It is a two byte unsigned value from 0 to 360 degrees.
// (0? is North, 90? is East, 180? is South and 270? is West.)
// Extra Temperatures 18 7 This field supports seven extra temperature stations. Each byte is one extra temperature value
// in whole degrees F with an offset of 90 degrees. For example, a value of 0 = -90?F ;
// a value of 100 = 10?F ; and a value of 169 = 79?F.
// Soil Temperatures 25 4 This field supports four soil temperature sensors, in the same format as the Extra Temperature
// field above
// Leaf Temperatures 29 4 This field supports four leaf temperature sensors, in the same format as the Extra Temperature
// field above
// Outside Humidity 33 1 This is the relative humitiy in %.
// Extra Humidities 34 7 Relative humidity in % for extra seven humidity stations.
// Rain Rate 41 2 This value is sent as 100th of a inch per hour. For example, 256 represent 2.56 inches/hour.
// UV 43 1 The unit is in UV index.
// Solar Radiation 44 2 The unit is in watt/meter2.
// Storm Rain 46 2 The storm is stored as 100th of an inch.
// Start Date of current Storm 48 2 Bit 15 to bit 12 is the month, bit 11 to bit 7 is the day and bit 6 to bit 0 is the year offseted
// by 2000.
// Day Rain 50 2 This value is sent as the 100th of an inch.
// Month Rain 52 2 This value is sent as the 100th of an inch.
// Year Rain 54 2 This value is sent as the 100th of an inch.
// Day ET 56 2 This value is sent as the 100th of an inch.
// Month ET 58 2 This value is sent as the 100th of an inch.
// Year ET 60 2 This value is sent as the 100th of an inch.
// Soil Moistures 62 4 The unit is in centibar. It supports four soil sensors.
// Leaf Wetnesses 66 4 This is a scale number from 0 to 15 with 0 meaning very dry and 15 meaning very wet. It supports
// four leaf sensors.
// Inside Alarms 70 1 Currently active inside alarms. See the table below
// Rain Alarms 71 1 Currently active rain alarms. See the table below
// Outside Alarms 72 2 Currently active outside alarms. See the table below
// Extra Temp/Hum Alarms 74 8 Currently active extra temp/hum alarms. See the table below
// Soil & Leaf Alarms 82 4 Currently active soil/leaf alarms. See the table below
// Transmitter Battery Status 86 1
// Console Battery Voltage 87 2 Voltage = ((Data * 300)/512)/100.0
// Forecast Icons 89 1
// Forecast Rule number 90 1
// Time of Sunrise 91 2 The time is stored as hour * 100 + min.
// Time of Sunset 93 2 The time is stored as hour * 100 + min.
// "
" <LF> = 0x0A 95 1
// "\r" <CR> = 0x0D 96 1
// CRC 97 2
// Total Length 99
if ($IPS_SENDER == "RegisterVariable") // wenn das Skript von einer RegisterVariable-Instanz aus aufgerufen worden ist
{
// $data = RegVar_GetBuffer($IPS_INSTANCE); // bereits im Puffer der RegisterVariable-Instanz vorhandene Daten in $data kopieren
$data = $IPS_VALUE; // neu empfangene Daten an $data anhängen
// http://www.koders.com/csharp/fid1BE60D81A18EF41535447F73BD3DE3BF846B5104.aspx?s=button
$DataStringHex = "L".$data;
$val = preg_replace('/[^
\x20-\x7E\xA0-\xFF]/', ' ', $DataStringHex);
$loo = substr($DataStringHex,0,3);
$barTrend = hexdec(strtohex(substr($DataStringHex,3,1)));
$barTrend = $barTrend - 256 * ($barTrend >> 7);
$barometerRaw = hexdec(strtohex(substr($DataStringHex,8,1).substr($DataStringHex,7,1)));
$barometer = (($barometerRaw*25.4)/1000);
$insideTempRaw =hexdec(strtohex(substr($DataStringHex,10,1).substr($DataStringHex,9,1)));
//$insideTempRaw = $insideTempRaw - 256 * ($insideTempRaw >> 7);
(int)$insideTemp = round(((($insideTempRaw/10) - 32) * (5/9)),2) ;
$insideHumidity =hexdec(strtohex(substr($DataStringHex,11,1)));
$outsideTempRaw =hexdec(strtohex(substr($DataStringHex,13,1).substr($DataStringHex,12,1)));
//$outsideTempRaw = $outsideTempRaw - 256 * ($outsideTempRaw >> 7);
(int)$outsideTemp = round(((($outsideTempRaw/10) - 32) * (5/9)),2) ;
$outsideHumidity =hexdec(strtohex(substr($DataStringHex,33,1)));
$windDirection = hexdec(strtohex(substr($DataStringHex,17,1).substr($DataStringHex,16,1)));
$currWindSpeed = hexdec(strtohex(substr($DataStringHex,14,1)));
$avgWindSpeed = hexdec(strtohex(substr($DataStringHex,15,1)));
$dayRain = hexdec(strtohex(substr($DataStringHex,51,1).substr($DataStringHex,50,1)));
$rainrate = hexdec(strtohex(substr($DataStringHex,42,1).substr($DataStringHex,41,1)));
$UV =hexdec(strtohex(substr($DataStringHex,43,1)));
$SolarRadiation = hexdec(strtohex(substr($DataStringHex,45,1).substr($DataStringHex,44,1)));
$StormRain = hexdec(strtohex(substr($DataStringHex,46,2)));
$ConsoleBatteryVoltageRaw = hexdec(strtohex(substr($DataStringHex,88,1).substr($DataStringHex,87,1)));
$ConsoleBatteryVoltage = round(((($ConsoleBatteryVoltageRaw * 300)/512)/100), 2);
$TransmitterBatteryStatus = hexdec(strtohex(substr($DataStringHex,86,1)));
$CRC = substr($DataStringHex,97,2);
if ($outsideTemp>70)
$outsideTemp=0;
if ($outsideHumidity >100)
$outsideHumidity=0;
setvalue(29183 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\Barometer]*/,$barometer);
setvalue(58383 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\currWindspeed]*/, $currWindSpeed);
setvalue(13794 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\InsideHumidity]*/, $insideHumidity);
setvalue(34430 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\InsideTemperature]*/, $insideTemp);
setvalue(29232 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\OutsideHumidity]*/, $outsideHumidity);
setvalue(53428 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\OutsideTemp]*/, $outsideTemp);
setvalue(18841 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\WindSpeedTenMinAverage]*/ , $avgWindSpeed);
setvalue(58383 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\currWindspeed]*/ , $currWindSpeed);
echo chr(13)."LOO :" . $loo .chr(13);
echo "barTrend :" . $barTrend .chr(13);
echo "barometer :" . $barometer . " mmHg" .chr(13);
echo "insideTemp :" . $insideTemp. " °C".chr(13);
echo "insideHumidity :" . $insideHumidity. "%" .chr(13);
echo "outsideTemp :" . $outsideTemp. " °C" .chr(13);
echo "outsideHumidity :" . $outsideHumidity. "%" .chr(13);
echo "windDirection :" . $windDirection .chr(13);
echo "currWindSpeed :" . $currWindSpeed .chr(13);
echo "avgWindSpeed :" . $avgWindSpeed .chr(13);
echo "dayRain :" . $dayRain .chr(13);
echo "rainrate :" . $rainrate .chr(13);
echo "UV :" . $UV .chr(13);
echo "SolarRadiation :" . $SolarRadiation .chr(13);
echo "StormRain :" . $StormRain .chr(13);
echo "ConsoleBatteryVoltage :" . $ConsoleBatteryVoltage .chr(13);
echo "TransmitterBatteryStatus :" . $TransmitterBatteryStatus.chr(13);
echo "CRC :" . $CRC .chr(13);
print " skript end";
}
function hextostr($x) {
$s='';
foreach(explode("
",trim(chunk_split($x,2))) as $h) $s.=chr(hexdec($h));
return($s);
}
function strtohex($x) {
$s='';
foreach(str_split($x) as $c) $s.=sprintf("%02X",ord($c));
return($s);
}
function hexdecs($hex)
{
// ignore non hex characters
$hex = preg_replace('/[^0-9A-Fa-f]/', '', $hex);
// converted decimal value:
$dec = hexdec($hex);
// maximum decimal value based on length of hex + 1:
// number of bits in hex number is 8 bits for each 2 hex -> max = 2^n
// use 'pow(2,n)' since '1 << n' is only for integers and therefore limited to integer size.
$max = pow(2, 4 * (strlen($hex) + (strlen($hex) % 2)));
// complement = maximum - converted hex:
$_dec = $max - $dec;
// if dec value is larger than its complement we have a negative value (first bit is set)
return $dec > $_dec ? -$_dec : $dec;
}
?>
und schliesslich werden die Graphen erstellt mit Hilfe eines leicht modifizierten Scripts von Meike (dazu müssen die Skripte von Meike natürlich installiert sein):
<?
// Multigraph mit GoogleChart V1.03
//
// Befehle für Liniengraphen
//
// Vari = geloggte Variablen-ID einsetzen "Vari[0]=>12345
// YAchse = Zuordnung Graph Y-Achse 0 oder 1 "YAchse[0]"=>0
// YBeschriftung = Y-Achsen Beschriftung z.B.°C oder % "YBeschriftung[0]"=>"°C"
// Zeitspanne = 1 = Tage, 2 = Wochen, 3 = Monate, 4 = Jahr "Zeitspanne"=>3
// Pfad = Zielordner für Graphen "Pfad"=>"C:/ip-symcon/media/"
// filename = Filename wird im Zielordner gespeichert "filename"=>"Test 2"
// Farben = Farben der Graphlinien "Farben[0]"=>"00008B"
// Size = Bildgrösse max. 30000 Bildpunkte 800x350 "Size"=>"800x350"
// Text = Beschreibung Graphen keine Eingabe = Variablename z.B. "Text[0]"=>"Wert 1"
// Ueberschrift = TitelGraph "Ueberschrift"=>"ÄÖÜßäöü"
// Endzeit = Endzeit Graph z.B. 06-03-2011 22:12 ""=jetzt "Endzeit"=>"06-03-2011 22:12"
// BoolOffset = Wert für Boolean-Variable = True
// Trans = Transparenz bei Grpahenfüllung z.B. 0 = keine Füllung 1..FF = Transparenzgrad
// Hinter1,Hinter2 = Hintergrundfarbe bei Angabe von Hinter2 Farbverlauf von Hinter1 nach Hinter2
// Schriftfarbe = Schriftfarbe Überschrift und Beschriftung X-,Y-Achse
// Dynamisch = 0=Dynamisch 1=Profil
// Graphenart = "Line" -Liniengraph "TimeCompare" -Linegraph verschiedene Zeiträume
// TimeCompare = Zeitverschiebung pro Variablen 0=keine Verschiebung 1=-1 Tag, 2=-1 Woche, 3 =-1 Monat, 4 =-1 Jahr
//
// Befehle für die Bargraphen
//
// Variablen als Zähler loggen!!
//
// Vari = geloggte Variablen-ID einsetzen "Vari[0]=12345
// YBeschriftung = Y-Achsen Beschriftung z.B.°C oder % "YBeschriftung[0]"=>"°C"
// Zeitspanne = 1 = Tage, 2 = Wochen, 3 = Monate, 4 = Jahr "Zeitspanne"=>3
// Pfad = Zielordner für Graphen "Pfad"=>"C:/ip-symcon/media/"
// filename = Filename wird im Zielordner gespeichert "filename"=>"Test 2"
// Farben[] = Farben der Graphlinien "Farben[0]"=>"00008B"
// Size = Bildgrösse max. 30000 Bildpunkte 800x350 "Size"=>"800x350"
// Text = Beschreibung Graphen keine Eingabe = Variablename z.B. "Text[0]"=>"Wert 1"
// Ueberschrift = TitelGraph "Ueberschrift"=>"ÄÖÜßäöü"
// Endzeit = Endzeit Graph z.B. 06-03-2011 22:12 ""=jetzt "Endzeit"=>"06-03-2011 22:12"
// Hinter1,Hinter2 = Hintergrundfarbe bei Angabe von Hinter2 Farbverlauf von Hinter1 nach Hinter2
// Schriftfarbe = Schriftfarbe Überschrift und Beschriftung X-,Y-Achse
// Graphenart = "Bar" -Bargraph
// Faktor = Faktor für Berechnung bei z.B. S0-Zähler
// TimeCompare = Zeitverschiebung pro Variablen 0=keine Verschiebung 1=-1 Tag, 2=-1 Woche, 3 =-1 Monat, 4 =-1 Jahr
//daily graph
$Vari = array (53428 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\OutsideTemp]*/);
$Trans = array (60);
$Farben = array ("0000ff");
$Text = array ("Outside Temperature");
$YBeschriftung = array ("°C");
$YAchse = array (0);
$Hinter1 = "000000";
$Hinter2 = "000000";
$Zeitspanne = 1;
$Pfad = "C:/IP-Symcon/media/";
$filename = "DailyOutsideTemperature";
$Size = "800x350";
$Endzeit = "";
$Ueberschrift= "Davis Wetterstation";
$BoolOffset = 0;
$Schriftfarbe = "ffffff";
$Dynamisch = 0;
$Graphenart = "Line";
$TimeCompare = array(0);
$Faktor = array(1);
include("GoogleCharts.ips.php");
//weekly graph
$Zeitspanne = 2;
$filename = "WeeklyOutsideTemperature";
include("GoogleCharts.ips.php");
//monthly graph
$Zeitspanne = 3;
$filename = "MonthlyOutsideTemperature";
include("GoogleCharts.ips.php");
//yearly graph
$Zeitspanne = 4;
$filename = "YearlyOutsideTemperature";
include("GoogleCharts.ips.php");
//daily graph pressure
$Vari = array (29183 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\Barometer]*/);
$Trans = array (60);
$Farben = array ("0000ff");
$Text = array ("Pressure");
$YBeschriftung = array ("mmHg");
$YAchse = array (1);
$Zeitspanne = 1;
$Pfad = "C:/IP-Symcon/media/";
$filename = "DailyPressure";
$Size = "800x350";
$Endzeit = "";
$Ueberschrift= "Davis Wetterstation";
$BoolOffset = 0;
$Schriftfarbe = "ffffff";
$Dynamisch = 1;
$Graphenart = "Line";
$TimeCompare = array(0);
$Faktor = array(1);
include("GoogleCharts.ips.php");
//weekly graph
$Zeitspanne = 2;
$filename = "WeeklyPressure";
include("GoogleCharts.ips.php");
//monthly graph
$Zeitspanne = 3;
$filename = "MonthlyPressure";
include("GoogleCharts.ips.php");
//yearly graph
$Zeitspanne = 4;
$filename = "YearlyPressure";
include("GoogleCharts.ips.php");
//daily graph outside humidity
$Vari = array (29232 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\OutsideHumidity]*/ );
$Trans = array (60);
$Farben = array ("0000ff");
$Text = array ("Moisture");
$YBeschriftung = array ("percent");
$YAchse = array (0);
$Zeitspanne = 1;
$Pfad = "C:/IP-Symcon/media/";
$filename = "DailyMoisture";
$Size = "800x350";
$Endzeit = "";
$Ueberschrift= "Davis Wetterstation";
$BoolOffset = 0;
$Schriftfarbe = "ffffff";
$Dynamisch = 1;
$Graphenart = "Line";
$TimeCompare = array(0);
$Faktor = array(1);
include("GoogleCharts.ips.php");
//weekly graph
$Zeitspanne = 2;
$filename = "WeeklyMoisture";
include("GoogleCharts.ips.php");
//monthly graph
$Zeitspanne = 3;
$filename = "MonthlyMoisture";
include("GoogleCharts.ips.php");
//yearly graph
$Zeitspanne = 4;
$filename = "YearlyMoisture";
include("GoogleCharts.ips.php");
//daily graph windspeed
$Vari = array (18841 /*[Wetterstation Dach\RegVarDavisTalkPacket\DavisTalkParsePacket\WindSpeedTenMinAverage]*/ );
$Trans = array (60);
$Farben = array ("0000ff","ff0000","000022");
$Text = array ("Wind speed (10-min averages)");
$YBeschriftung = array ("m/s");
$YAchse = array (0);
$Zeitspanne = 1;
$Pfad = "C:/IP-Symcon/media/";
$filename = "DailyAverageWindSpeed";
$Size = "800x350";
$Endzeit = "";
$Ueberschrift= "Davis Wetterstation";
$BoolOffset = 0;
$Schriftfarbe = "ffffff";
$Dynamisch = 1;
$Graphenart = "Line";
$TimeCompare = array(0);
$Faktor = array(1);
include("GoogleCharts.ips.php");
//weekly graph
$Zeitspanne = 2;
$filename = "WeeklyAverageWindSpeed";
include("GoogleCharts.ips.php");
//monthly graph
$Zeitspanne = 3;
$filename = "MonthlyAverageWindSpeed";
include("GoogleCharts.ips.php");
//yearly graph
$Zeitspanne = 4;
$filename = "YearlyAverageWindSpeed";
include("GoogleCharts.ips.php");
?>