simple_weather_app
This is an old revision of the document!
Simple Weather App
Sep 2026
Back to Micro Python
Introduction
- download
{{ :weatherapppico.png?500 |}} \\ This project is a bit of an accident. We want to make a new clock, we made one around 10 years ago from a Raspberry Pi Zero and some 7 segment LEDs. That project can be found here - [[raspberry_pi_led_clock_and_ntp_server|Raspberry Pi LED Clock and NTP Server]]. \\ \\ Now, it has worked flawlessly for 10 years. But it is still a small computer with an OS, and you have to do some maintenance on the OS (upgrades etc) periodically. So the thinking was, a new clock using a Raspberry Pi Pico would be cool, newer hardware, no OS worries, better display (LCD rather than 7 segment) and include other things than the time like the weather, or a news feed etc. \\ \\ The first thing we explored was how to get the weather from the internet, turns out this is pretty simple. We used something called Open Meto, which is: * Open-Meteo is a free, open-source weather API that delivers localized weather forecasts and historical climate data without requiring an API key. So basically a free weather service to pull information from using an API. \\ \\ If you wish to make one of these, then great. Please check out the Project called 'Network Analyzer' and look at Phase 2 (which is the LCD we are using). \\ \\ You will need: * The same LCD. * The Same Driver. * The Test Code for the Driver Check out this link: [[pico_with_2.4_tenstar_spi_lcd|Pico with 2.4" Tenstar SPI LCD]]. This will ensure your hardware is good, before you start to worry about the software. \\ \\ ---- ==== A Simple Test ==== \\ If you have completed the hardware setup, and see some test text on your LCD, then we are good to start. The first test is to get some weather data from Open-Meteo. Now, this means connecting to the internet from your Pico, so please ensure you have done the following: * [[connect_pico_to_wifi|Connect Pico to Wifi]] * [[find_pico_mac_address|Find Pico MAC Address]] This will ensure you have tested your Pico Wifi and you have your MAC address in case your router requires this. \\ \\ ---- ==== Test Open-Meteo ==== \\ From Thonny, save this code to your Pico as Meteo-test and run it. \\ \\ <code:python | download> import network import urequests import time # --- CONFIGURATION --- WIFI_SSID = "YOUR_WIFI_SSID" WIFI_PASS = "YOUR_WIFI_PASSWORD" # Coordinates (e.g., London: lat=51.5074, lon=-0.1278) LATITUDE = "51.5074" LONGITUDE = "-0.1278" # Open-Meteo API URL for temperature, humidity, and weather code URL = f"http://api.open-meteo.com/v1/forecast?latitude={LATITUDE}&longitude={LONGITUDE}¤t_weather=true" def connect_wifi(): wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print(f"Connecting to Wi-Fi network: {WIFI_SSID}...") wlan.connect(WIFI_SSID, WIFI_PASS) timeout = 10 while not wlan.isconnected() and timeout > 0: print("Waiting for connection...") time.sleep(1) timeout -= 1 if wlan.isconnected(): print("Connected successfully!") print("Network status/IP:", wlan.ifconfig()) return True else: print("Failed to connect to Wi-Fi.") return False def fetch_weather(): print("Fetching weather data...") try: response = urequests.get(URL) if response.status_code == 200: data = response.json() current = data.get("current_weather", {}) temp = current.get("temperature") windspeed = current.get("windspeed") weathercode = current.get("weathercode") print("\n--- WEATHER DATA RECEIVED ---") print(f"Temperature: {temp} °C") print(f"Wind Speed: {windspeed} km/h") print(f"Weather Code: {weathercode}") print("-----------------------------\n") else: print(f"Error: Server responded with status code {response.status_code}") response.close() except Exception as e: print("Error fetching data:", e) # --- RUN TEST --- if connect_wifi(): fetch_weather()
simple_weather_app.1789050987.txt.gz · Last modified: by walkeradmin
