Software only solution for feeding weather data
Submitted by mharizanov on Sun, 15/04/2012 - 20:06You may be interested in gathering weather data but lack the hardware to measure humidity, air pressure, dew point temperature, wind speed and so forth. The weather data added over power consumption via a multigraph reveals quite interesting tendencies, worth giving a try.
My solution was to create an "Stratus Developer" free API key for weather underground and then a small PHP script to collect the data and post to emoncms. You get 500 queries a day so you can afford running the script 20 times an hour or every three minutes, just set up a cron job to do it for you.
http://www.wunderground.com/weather/api/
Here is my code:
<html>
<?php
//http://www.wunderground.com/weather/api/d/documentation.html
//Change the weather underground API and city below
$json_string = file_get_contents("http://api.wunderground.com/api/****API***/geolookup/conditions/q/***MY CITY NAME****.json");
$parsed_json = json_decode($json_string);
$location = $parsed_json->{'location'}->{'city'};
$temp_c = $parsed_json->{'current_observation'}->{'temp_c'};
$relative_humidity = $parsed_json->{'current_observation'}->{'relative_humidity'};
$pressure_mb = $parsed_json->{'current_observation'}->{'pressure_mb'};
$wind_kph = $parsed_json->{'current_observation'}->{'wind_kph'};
echo "Current temperature in ${location} is: ${temp_c}<br>";
echo "Current relative humidity in ${location} is: ${relative_humidity}<br>";
echo "Current pressure in ${location} is: ${pressure_mb}<br>";
echo "Current wind speed in ${location} is: ${wind_kph}<br>";
//Change the URL and EmonCMS API below
$url = 'http://***********/emoncms3/api/post?apikey=***EMONCMS_API*****&json={humidity:' . $relative_humidity . ',pressure:' . $pressure_mb . ',wind:' . $wind_kph . ',temp:' . $temp_c .'}';
echo $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch);
?>
</html>
Re: Software only solution for feeding weather data
Great idea! thanks for posting you code mharizanov