This file receives the data from the Ambient Weather WS-1200-IP ObserverIP and sends the data to wunderground, as well as to weewx.
For more details, read the blog write up here: http://obrienlabs.net/redirecting-weather-station-data-from-observerip/
<?php
// Parse the wunderground packets sent from the ObserverIP
// Pat O'Brien, 1/14/2016
// The ObserverIP does not provide heat index data in its packet, this will calculate it
// Formula from NOAA http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
function heatindex($T, $RH) {
$HI = -42.379 + 2.04901523*$T + 10.14333127*$RH - .22475541*$T*$RH - .00683783*$T*$T - .05481717*$RH*$RH + .00122874*$T*$T*$RH + .00085282*$T*$RH*$RH - .00000199*$T*$T*$RH*$RH;
return round( $HI, 1 );
}
// Make sure the ID and PASSWORD fields match what we think it should match. If it does, this update is valid and continue.
if ( ($_GET["ID"] == "YOUR_WUNDERGROUND_USERNAME") && ($_GET["PASSWORD"] == "YOUR_WUNDERGROUND_PASSWORD") ) {
//============================================//
// Auto send data query right to wunderground //
//============================================//
$wunderground = file_get_contents("http://rtupdate.wunderground.com/weatherstation/updateweatherstation.php?" . $_SERVER['QUERY_STRING']);
echo $wunderground;
//==============================================//
// Write data to ncat socket for use with weewx //
//==============================================//
$heatindex = heatindex($_GET['tempf'], $_GET['humidity']);
$socket = "outTemp=".$_GET['tempf'].",";
$socket .= "outHumidity=".$_GET['humidity'].",";
$socket .= "dewpoint=".$_GET['dewptf'].",";
$socket .= "windchill=".$_GET['windchillf'].",";
//$socket .= "heatindex=".$heatindex.","; // Enable heat index if you need it. WeeWx and other systems will provide this for you.
$socket .= "windDir=".$_GET['winddir'].",";
$socket .= "windSpeed=".$_GET['windspeedmph'].",";
$socket .= "windGust=".$_GET['windgustmph'].",";
//$socket .= "rain=".$_GET['rainin'].","; // This is really rain rate
$socket .= "dailyrain=".$_GET['dailyrainin'].",";
$socket .= "radiation=".$_GET['solarradiation'].",";
$socket .= "UV=".$_GET['UV'].",";
$socket .= "inTemp=".$_GET['indoortempf'].",";
$socket .= "inHumidity=".$_GET['indoorhumidity'].",";
$socket .= "barometer=".$_GET['baromin'].",";
$socket .= "epoch=".time().",";
$socket .= "txBatteryStatus=".$_GET['lowbatt']; // Last item, no comma
$socket .= PHP_EOL;
// Send data to the socket middle man for weewx to archive
$fp = fsockopen("localhost", 2999);
if ($fp) {
fwrite($fp, $socket);
fclose ($fp);
}
} else {
header('HTTP/1.0 401 Unauthorized');
echo 'failure';
die();
}
?>