Community
OpenEnergyMonitor

Community

[WORKING] weatherstation import from oberservip to emonpi

Tags: #<Tag:0x00007fc922f43740> #<Tag:0x00007fc922f43650>

Hello,
maybe someone wants to do that as well …

i have a ambient weather station, and wanted to integrate that into emoncms …
as i know my weatherstation: WS-2902A is providing weatherdata via livedata.html, but i wanted that it is writing directly to it …
and as i know it is writing data to wunderworld and ambientweather.com.
so, i decided to write it once to ambientweather my account and will use the wunderworld weather to send this data to my emonpi.
is working smooth :slight_smile:

1.) changed the DNS name for “rtupdate.wunderground.com” to IP address of emonpi on my local DNS server (on almost every router you can define your own host names + ip)
2.) configured in OBSERVIP the wunderground account with username + password (this you need to adjust in the php script - see below, you can take whatever you want, as it will not be sent to wunderground in real)
3.) wrote a php script and put it to a new folder on emonpi: /var/www/html/weatherstation and named the php script: (adapt IP to your

updateweatherstation.php (i formated the values to mm, m/sec, °C)
here the file:

<?php

// Parse the wunderground packets sent from the ObserverIP
// 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 );
}

if ( ($_GET["ID"] == "<USERNAME-FOR-WUNDERGROUND>") && ($_GET["PASSWORD"] == "PASSWORD-FOR-WUNDERGROUND") ) {
$heatindex = heatindex($_GET['tempf'], $_GET['humidity']);
$data = array(
    'outTemp=' => (($_GET['tempf'] - 32) / 1.8),
    'outHumidity' => $_GET['humidity'],
    'dewpoint' => (($_GET['dewptf'] - 32) / 1.8),
    'windchill' => (($_GET['windchillf'] - 32) / 1.8),
    'heatindex' => (($heatindex - 32) / 1.8),
    'windDir' => $_GET['winddir'],
    'windSpeed' => ($_GET['windspeedmph'] * 0.44704),
    'windGust' => ($_GET['windgustmph'] * 0.44704),
    'rain' => ($_GET['rainin'] * 25.4),
    'dailyrain' => ($_GET['dailyrainin'] * 25.4),
    'weeklyrain' => ($_GET['weeklyrainin'] * 25.4),
    'monthlyrain' => ($_GET['monthlyrainin'] * 25.4),
    'yearlyrain' => ($_GET['yearlyrainin'] * 25.4),
    'radiation' => $_GET['solarradiation'],
    'UV' => $_GET['UV']
//    'inTemp' => (($_GET['indoortempf'] - 32) / 1.8),
//    'inHumidity' => $_GET['indoorhumidity'] * 25,4),
//    'barometer' => $_GET['baromin'],
//    'txBatteryStatus' => $_GET['lowbatt'],
//    'softwaretype' => $_GET['softwaretype'],
//    'action' => $_GET['action'],
//    'realtime' => $_GET['realtime'],
//    'rtfreq' => $_GET['rtfreq']
);
$payload = json_encode($data);

//API URL
$url = 'http://<YOUR-IP-FROM-EMONPI>/emoncms/input/post?node=weatherstation&fulljson='.$payload.'&apikey=<PUT_HERE-YOUR API_CODE>';
$result = file_get_contents($url, false);
echo 'result:'.$result;

} else {
	header('HTTP/1.0 401 Unauthorized');
    echo 'wrong data provided - failure';
    die();
}

?>

Hi Erwin, welcome and thanks for sharing.

For future reference, when posting code or bash output, put in 3 ‘backticks’ (found at the top left of the keyboard normally) on a line on their own, then the code, then 3 more backticks on a line following the code.

    ```
    code
    ```

If it is something like php you can add a language identifier that after the first 3 backticks so ```php

Cheers