from machine import Pin, I2C
import ssd1306
import urequests
#connecting to wifi
import network
import time
print("Connecting to WiFi", end="")
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('Wokwi-GUEST', '')
while not sta_if.isconnected():
print(".", end="")
time.sleep(0.1)
print(" Connected!")
#doing request and response
ok=True
lat=float(input("Enter latitude:"))
lon=float(input("Enter longitude:"))
if lat>90 or lat<-90:
print("latitude should be between -90 to 90")
ok=False
if lon>179 or lon<-179:
print("longitude should be between -179 to 179")
ok=False
if ok==True:
url="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".format(latitude=lat,longitude=lon)
response=urequests.get(url)
url_dict=response.json()
t=url_dict["current"]["time"][11:]
temp=url_dict["current"]["temperature_2m"]
ws=url_dict["current"]["wind_speed_10m"]
print("Time in GMT is:",t)
print("temperature is:",temp)
print("wind speed is:",ws)
#for displaying in oled
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
oled.text('Time:{time}'.format(time=t), 0, 10)
oled.text('Temp:{temp}'.format(temp=temp),0,20)
oled.text('Wind speed:{ws}'.format(ws=ws),0,30)
oled.show()