This is actually a reworking of something I made years ago that uses a servo to show the weather forecast for my area. Previously I used an Arduino with Ethernet and had to have it constantly plugged in to the mains. Now with Electric Imp it’s all wifi, much smaller and all batteries, going into a deep sleep and waking up every hour to get the forecast.
Once the beta is over I’ll post the code and laser cut parts but in the meantime here’s a link to a quick Vine of it in action. (Making a slight iteration so I’ll have a laser etched arrow on the front).
Beats my dull LCD weather display by a huge country mile.
How would you show barometric pressure?
I’ve found some local, as in down the road, weather stns on weatherunderground API quite easy to work with.
PHP can parse any of the dozens of XML tags that they offer and feed their values to the imp.
In my usage, the imp makes a request every 2 minutes to find out if it’s daytime or nighttime, or how close it is to those times … if I decide to alter lighting conditions 30 minutes before sunrise (for example).
My example uses beta Agents, so I don’t think I can post code until the beta testing is over.
If you view the Yahoo Weather XML (complete result), you’ll see all of the tags available.
But Weather Underground is great too! They might offer things that Yahoo does not.
I can post the PHP code … You need to give it your WOEID (where on earth am I ID)
// Use PHP CURL to get XML data for defined WOEID …
// This is my woe ID, go to Yahoo Weather and find the ID for your location.
$woeid=“12781675”;
$feed_url = “http://weather.yahooapis.com/forecastrss?w=”.$woeid;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"$feed_url");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
$xml = curl_exec($curl);
curl_close($curl);
$weather = simplexml_load_string($xml);
if(!$weather) die(‘weather failed’);
$copyright = $weather->channel->copyright;
$channel_yweather = $weather->channel->children(“http://xml.weather.yahoo.com/ns/rss/1.0”);
foreach($channel_yweather as $x => $channel_item) {
foreach($channel_item->attributes() as $k => $attr){
$yw_channel[$x][$k] = $attr;
if($x==“astronomy” && $y=“sunrise”){$sr=$yw_channel[$x][$y];}
if($x==“astronomy” && $y=“sunset”){$ss=$yw_channel[$x][$y];}
}
}
echo "Sunrise: ".$sr;
I’m only looking for ‘astronomy/sunrise’ tags, but you can look at any of them.
It’s great to see alternate methods … as many different scripts as we can get would be good. I see these “snippets” of code being important for someone in the future. Hopefully we’ll have a central place to put all of them eventually.