# ESP32 OLED Weather Display (MicroPython) # 2026 Iffy Books (wtfpl) # https://iffybooks.net/esp32-breadboard-display from machine import Pin, I2C import ssd1306 import time import network import requests import json i2c = I2C(-1, scl=Pin(22), sda=Pin(21)) # ESP32 pins oled_width = 128 oled_height = 64 oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c) # Wi-Fi credentials ssid = '' password = '' # Connect to network def connect_wifi(ssid, password): # Connect to your network station = network.WLAN(network.STA_IF) station.active(True) station.connect(ssid, password) # Wait for connection timeout = 10 while not station.isconnected() and timeout > 0: time.sleep(1) timeout -= 1 if station.isconnected(): print('Connection successful') print(station.ifconfig()) return True else: print('Connection failed. Timeout reached') return False # Infinite loop while True: if connect_wifi(ssid, password): # Make GET request try: # Download local weather in JSON format response = requests.get("https://wttr.in/philadelphia?format=j1") # Get response code response_code = response.status_code except: try: response = requests.get("https://wttr.in/philadelphia?format=j1") except Exception as e: print(e) # Convert JSON string to dictionary data = json.loads(response.text) current_temp = data['current_condition'][0]['temp_F'] current_feel = data['current_condition'][0]['FeelsLikeF'] pressure = data['current_condition'][0]['pressure'] moon_phase = data['weather'][0]['astronomy'][0]['moon_phase'] nine_am_temp = data['weather'][0]['hourly'][3]['tempF'] noon_temp = data['weather'][0]['hourly'][4]['tempF'] three_pm_temp = data['weather'][0]['hourly'][5]['tempF'] six_pm_temp = data['weather'][0]['hourly'][6]['tempF'] nine_pm_temp = data['weather'][0]['hourly'][7]['tempF'] oled.text("Now " + str(current_temp) + "F Feel " + str(current_feel) + "F", 0, 0) oled.text('9AM '+str(nine_am_temp) + "F 12PM " + str(noon_temp) + "F", 0, 12) oled.text('3PM '+str(three_pm_temp) + "F 6PM " + str(six_pm_temp) + "F", 0, 24) oled.text('9PM '+str(nine_pm_temp) + "F P " + str(pressure), 0, 36) oled.text(moon_phase, 0, 48) oled.show() print("Success!") time.sleep(15*60) # Sleep 15 minutes