Arduino “having11” Guy
Published © GPL3+

Real-Time Weather with Raspberry Pi 4

View current weather data by using the OpenWeatherMap API along with the new Raspberry Pi 4.

BeginnerFull instructions provided1 hour9,762
Real-Time Weather with Raspberry Pi 4

Things used in this project

Hardware components

Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
×1

Software apps and online services

Openweathermap
VS Code
Microsoft VS Code

Story

Read more

Schematics

Schematic

Code

Weather Viewer

Python
import time
import requests
from pprint import pprint

settings = {
    'api_key':'<API KEY>',
    'zip_code':'<ZIP Code>',
    'country_code':'us',
    'temp_unit':'imperial'} #unit can be metric, imperial, or kelvin

BASE_URL = "http://api.openweathermap.org/data/2.5/weather?appid={0}&zip={1},{2}&units={3}"

while True:
    final_url = BASE_URL.format(settings["api_key"],settings["zip_code"],settings["country_code"],settings["temp_unit"])
    weather_data = requests.get(final_url).json()
    pprint(weather_data)
    time.sleep(20) #get new data every 20 seconds

Credits

Arduino “having11” Guy

Arduino “having11” Guy

64 projects • 374 followers
IoT and embedded systems enthusiast. Also an intern at Hackster.io who loves working on projects and sharing knowledge.

Comments