Martin's corner on the web

Software only solution for feeding weather data to emoncms

I have installed emoncms to try it as alternative to my own data visualization software. It is quite nice piece of software and is open source.

I then wanted to gather 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.

Here is my code:



//Change the weather underground API and city below
$json_string = file_get_contents("****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}";
echo "Current relative humidity in ${location} is: ${relative_humidity}";
echo "Current pressure in ${location} is: ${pressure_mb}";
echo "Current wind speed in ${location} is: ${wind_kph}";

//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);


7 thoughts on “Software only solution for feeding weather data to emoncms

  1. Pingback: What is this all about? | Martin's corner on the web

  2. Pingback: Using my 1.8 TFT as a Raspberry Pi status display | Martin's corner on the web

  3. Francesco


    I try yours php script and the script works very well, but I have some problem to create a Graph (like yours) with emoncms can you help me ?
    Please let me know


  4. Pingback: 3D printed Stevenson screen | Martin's corner on the web

  5. Pingback: Martin's corner on the web

  6. Pingback: MQTT topic tree structure improvements | Martin's corner on the web