import network
import ssd1306
import time
import urequests
from machine import I2C, Pin
import json
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
def connect_to_wifi():
wifi.connect('Wokwi-GUEST', '')
time.sleep(5)
if wifi.isconnected():
print("Successfully connected to:", wifi.config('essid'))
print("IP Address:", wifi.ifconfig()[0])
else:
print("Not connected")
print("Connection status:", wifi.status())
connect_to_wifi()
connect_to_wifi()
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
latitude = float(input("Latitude: "))
longitude = float(input("Longitude: "))
while True:
weather_api = urequests.get(f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}¤t=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m")
weather = weather_api.json()
current_time = weather.get('current', {}).get('time')
reversedate = current_time[:10]
Time = current_time[current_time.find("T")+1:]
year = current_time[:4]
month = current_time[4:7]
day = current_time[8:10]
temperature = weather.get('current',{}).get('temperature_2m')
wind_speed = weather.get('current',{}).get('wind_speed_10m')
oled.text("Hello,Mr.Stark!",0,0)
oled.text("Live Weather:",0,30)
oled.text("Time: ",0,10)
oled.text(Time,40,10)
oled.text("Date: ",0,20)
oled.text(f"{day}{month}-{year}",40,20)
oled.text(f"Temp:{str(temperature)} C",0,40)
oled.text(f"Wind: {str(wind_speed)} Km/hr",0,50)
time.sleep(5)
oled.show()