element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
BeagleBoard
  • Products
  • Dev Tools
  • Single-Board Computers
  • BeagleBoard
  • More
  • Cancel
BeagleBoard
Blog Do you need an umbrella today?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join BeagleBoard to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: markvenn
  • Date Created: 1 Dec 2014 10:55 PM Date Created
  • Views 834 views
  • Likes 1 like
  • Comments 4 comments
  • python
  • mark_venn
  • weather
  • beaglebone-black
Related
Recommended

Do you need an umbrella today?

markvenn
markvenn
1 Dec 2014

I have been working on an idea for my project. I am using my BBB to get the weather forecast and to let me know if I need to take an umbrella when I go out. (To be honest I don't use an umbrella but this is is for a "proof of concept" idea). image

 

I am using python here to collect the forecast from Weather Underground, the api page is very helpful, and when I have the forecast as a json document I can extract the data I am looking for and do stuff with it. Currently I am displaying the weather forecast form my local area for the day that the program is being run and the next day. I have coded the place that I want the weather for into the string that makes up the URL, as my project is going to be setup per user I think that this is OK. See code below:

 

# program to grab the weather forecast from weather underground
# author Mark Venn
# based on code from "Getting Started with Raspberry Pi"
# currently collects the forecast for current day and next day. Lights an LED if the chances of rain are over 60%

# imports
import requests
import Adafruit_BBIO.GPIO as GPIO
import time

# configure GPIO pins
GPIO.setup("P8_8",GPIO.OUT)

GPIO.output("P8_8",GPIO.LOW)

# wunderground api key

key = 'xxxxxxxxxxxxxxxx'

# build string using hard coded web address & api key variable
ApiUrl = 'http://api.wunderground.com/api/' + key + '/geolookup/forecast/q/UK/Bembridge.json'

while True:

    # get the weather forecast from wunderground and store in variable
    r = requests.get(ApiUrl)

    # take response and parse it into python dictionary object
    forecast = r.json

    # extract relevant data.
    # use variable to collect day of the week
    day = forecast['forecast']['txt_forecast']['forecastday'][0]['title']
    # display next day
    nextDay = forecast['forecast']['txt_forecast']['forecastday'][2]['title']

    # chance of rain
    rain = forecast['forecast']['txt_forecast']['forecastday'][0]['pop']
    rain = int(rain)

    # display current day
    print day

    #directly display the required info
    print forecast['forecast']['txt_forecast']['forecastday'][0]['fcttext']


    print nextDay
    # TEST CODE
    # print rain

    #directly display the required info
    print forecast['forecast']['txt_forecast']['forecastday'][2]['fcttext']

    if rain >= 60:
        GPIO.output("P8_8",GPIO.HIGH)
    else:
        GPIO.output("P8_8",GPIO.LOW)

    time.sleep(180)


# TEST CODE #
# prints entire json document
#print forecast

The data I need for the forecast is held in fcttext in 2 key / value pairs and this is displayed.

root@beaglebone:~# python text_forecast_v3.py

Monday

Mostly cloudy. Lows overnight in the low 40s.

Tuesday

Cloudy and becoming windy. Periods of light rain early. Turning colder. High 46F. Winds N at 20 to 30 mph. Chance of rain 40%.

Monday

Mostly cloudy. Lows overnight in the low 40s.

Tuesday

Cloudy and becoming windy. Periods of light rain early. Turning colder. High 46F. Winds N at 20 to 30 mph. Chance of rain 40%.

Monday

Cloudy. Lows overnight in the low 40s.

Tuesday

Light rain early. Then becoming windy in the afternoon. Turning colder. High 47F. Winds N at 20 to 30 mph. Chance of rain 40%.

 

I am displaying this in the console at the moment, I might use some kind of GUI at a later date; my son odion is often telling me that I should put stuff into GUIs but A console is good enough for me for now image

The code to get the forecast could be run on any machine that can run python 2.7 but now we come to the reason for running this on the BBB. There is a single LED connected to P8-8 and when the value of the precipitation chance in percentage is over  60% this LED lights up. The whole check is done every 3 minutes at the moment but I will be playing with the timings later. It is likely that I can get away with every 6 hours or so but I will see.

image

I have taken the idea for this from the "Getting Started with Raspberry Pi" book and made a few changes as well as converting it to the BBB; I will probably set this up on the Pi next and see if there are any differences in the way it works.

The Weather Underground api looks very wide ranging and I will see what else I can get out of it, I think that as we in the UK head into winter something that pulls the expected maximum and minimum temperatures will be useful. I have found where this info is held in the json document:

"period":1,

"high": {

"fahrenheit":"48",

"celsius":"8"

},

"low": {

"fahrenheit":"41",

"celsius":"5"

}

Will have to play around with this info and see how I can make use of it.

 

I will be using my BB_VIEW display to see how I can display the info, not sure what or how yet, this will be in another blog. I am going to be writing about my experiences with my new Pi B+ so check out my blogs on there.

Bye for now, off to check if my LED is alight yet!

 

Beaglebone Black

BB View 4_3 LCD Display

  • Sign in to reply

Top Comments

  • DAB
    DAB over 11 years ago +1
    Good post. Where I live, I always carried an umbrella. Our weather was very changeable and afternoon thunderstorms were common during the summer. DAB
  • DAB
    DAB over 11 years ago in reply to markvenn +1
    Hi Mark, Set it up for Dayton, Ohio and you will get a good lesson in variable weather. We sometimes see temperature changes of 40 to 50 degrees F in the course of the day. Thanks. DAB
  • markvenn
    markvenn over 11 years ago in reply to DAB

    Dayton weather, 10 minutes apart, each line is :

    root@beaglebone:~# vi text_forecast_v3.py

    root@beaglebone:~# python text_forecast_v3.py

    Thursday

    Cloudy skies. Slight chance of a rain shower. High around 40F. Winds E at 5 to 10 mph.

    Friday

    Showers early, becoming a steady rain later in the day. High 46F. Winds light and variable. Chance of rain 100%. Rainfall near a quarter of an inch.

    Thursday

    Cloudy skies. Slight chance of a rain shower. High around 40F. Winds E at 5 to 10 mph.

    Friday

    Showers early, becoming a steady rain later in the day. High 46F. Winds light and variable. Chance of rain 100%. Rainfall near a quarter of an inch.

    Thursday

    Cloudy skies. Slight chance of a rain shower. High around 40F. Winds E at 5 to 10 mph.

    Friday

    Showers early, becoming a steady rain later in the day. High 46F. Winds light and variable. Chance of rain 100%. Rainfall near a quarter of an inch.

    Thursday

    Cloudy. Slight chance of a rain shower. High near 40F. Winds E at 5 to 10 mph.

    Friday

    Showers early, becoming a steady rain later in the day. High 46F. Winds light and variable. Chance of rain 100%. Rainfall around a quarter of an inch.

    Thursday

    Cloudy. Slight chance of a rain shower. High near 40F. Winds E at 5 to 10 mph.

    Friday

    Showers early, becoming a steady rain later in the day. High 46F. Winds light and variable. Chance of rain 100%. Rainfall around a quarter of an inch.

    Thursday

    Cloudy. Slight chance of a rain shower. High near 40F. Winds E at 5 to 10 mph.

    Friday

    Showers early, becoming a steady rain later in the day. High 46F. Winds light and variable. Chance of rain 100%. Rainfall around a quarter of an inch.

    Thursday

    Cloudy. Slight chance of a rain shower. High near 40F. Winds E at 5 to 10 mph.

    Friday

    Showers early, becoming a steady rain later in the day. High 46F. Winds light and variable. Chance of rain 100%. Rainfall around a quarter of an inch.

    Thursday

    Cloudy skies. Slight chance of a rain shower. High near 40F. Winds E at 5 to 10 mph.

    Friday

    Showers early, becoming a steady rain later in the day. High 46F. Winds light and variable. Chance of rain 100%. Rainfall around a quarter of an inch.

    Thursday

    Cloudy skies. Slight chance of a rain shower. High near 40F. Winds E at 5 to 10 mph.

    Friday

    Showers early, becoming a steady rain later in the day. High 46F. Winds light and variable. Chance of rain 100%. Rainfall around a quarter of an inch.

    Thursday

    Cloudy skies. Slight chance of a rain shower. High near 40F. Winds E at 5 to 10 mph.

    Friday

    Showers early, becoming a steady rain later in the day. High 46F. Winds light and variable. Chance of rain 100%. Rainfall around a quarter of an inch.

    Thursday

    Cloudy skies. Slight chance of a rain shower. High near 40F. Winds E at 5 to 10 mph.

    Friday

    Showers early, becoming a steady rain later in the day. High 46F. Winds light and variable. Chance of rain 100%. Rainfall around a quarter of an inch.

    Thursday

    Generally cloudy. Slight chance of a rain shower. High near 40F. Winds E at 5 to 10 mph.

    Friday

    Rain showers in the morning will evolve into a more steady rain in the afternoon. High 47F. Winds light and variable. Chance of rain 100%. Rainfall around a quarter of an inch.

     

    Definitely need your umbrella tomorrow! image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 11 years ago in reply to markvenn

    Hi Mark,

     

    Set it up for Dayton, Ohio and you will get a good lesson in variable weather.

     

    We sometimes see temperature changes of 40 to 50 degrees F in the course of the day.

     

    Thanks.

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • markvenn
    markvenn over 11 years ago in reply to DAB

    Hi DAB

    Give me a town in your area and I will see what the data looks like! Extreme weather would be good to try.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 11 years ago

    Good post.

     

    Where I live, I always carried an umbrella.  Our weather was very changeable and afternoon thunderstorms were common during the summer.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube