Evan Rust
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 hour25,018
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

Evan Rust

Evan Rust

122 projects • 1087 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments