Raspberry Pi Weather station (in 5 mins)
It’s displaying weather forecast for Cambridge, UK. That’s a miserable weather indeed :). As you can guess, the first line is the current condition followed by next two day’s forecast which includes high and low temperatures (in Celsius). The last line is the date and time of update.
The awesome bit is you can make this with 20 lines of scripting and in less than 5 mins. Here is how it works:
- Grabs the weather data from Yahoo weather feed.
- Extracts key weather data from the xml feed, and
- Displays the data to the LCD.
The whole thing is done with this shell script (which I’m sure can be further reduced a lot):
Most of the script above is for converting the rss weather feed xml into those few lines to display. It writes the information in a file which is then read and displayed to LCD by a python script. Here’s the python script to display the info in green color only:
- #!/usr/bin/env python
- from pylcdsysinfo import BackgroundColours, TextColours, TextAlignment, TextLines, LCDSysInfo
- from time import sleep
- d = LCDSysInfo(); d.clear_lines(TextLines.ALL, BackgroundColours.BLACK)
- d.dim_when_idle(False);d.set_brightness(127);d.save_brightness(127, 255)
- f = open(‘yw’, ‘r’); col = TextColours.GREEN; c = 1;
- for line in f:
- d.display_text_on_line(c, line, False, TextAlignment.LEFT, col)
- c = c + 1
That’s 20 lines of scripting doing it all! Yet another example of how awesome shell and python scripts are.
You can run this every hour simply by adding a cron job. There is a bit of details involved before you can use this code. You need the python lib for the LCD and also a bit of info on how Yahoo weather feed works: http://developer.yahoo.com/weather/. To get the forecast for your location, you need the WOEID (Google: WOEID finder) and to pass it to the Yahoo weather feed url.
I understand I should provide detailed steps for beginners, perhaps as an instructable. If you want to see the detailed steps, do let me know in the comments :).