import network
import urequests
import json
def connect_wifi(ssid, password):
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while not wlan.isconnected():
print("Connecting to WiFi...")
time.sleep(1)
print("Connected to WiFi", wlan.ifconfig())
def get_weather(api_key, city):
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
response = urequests.get(url)
data = json.loads(response.text)
temperature = data['main']['temp']
humidity = data['main']['humidity']
return temperature, humidity
coef_temp = 0.5
coef_humidity = -0.2
intercept = 15
def predict_next_hour(temp, humidity):
next_temp = coef_temp * temp + coef_humidity * humidity + intercept
return next_temp
def classify_weather(temp, humidity):
if temp > 25 and humidity < 60:
return "Sunny"
elif humidity > 80:
return "Rainy"
else:
return "Cloudy"
connect_wifi('********', 'xucgkudwetr,.')
api_key = '*************'
city = 'your_city'
while True:
temp, humidity = get_weather(api_key, city)
next_temp = predict_next_hour(temp, humidity)
weather = classify_weather(next_temp, humidity)
print(f"Current Temp: {temp}°C, Humidity: {humidity}%")
print(f"Predicted Next Hour Temp: {next_temp}°C")
print(f"Predicted Weather: {weather}")
time.sleep(3600)
import network
import urequests
import json
def connect_wifi(ssid, password):
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while not wlan.isconnected():
print("Connecting to WiFi...")
time.sleep(1)
print("Connected to WiFi", wlan.ifconfig())
def get_weather(api_key, city):
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
response = urequests.get(url)
data = json.loads(response.text)
temperature = data['main']['temp']
humidity = data['main']['humidity']
return temperature, humidity
coef_temp = 0.5
coef_humidity = -0.2
intercept = 15
def predict_next_hour(temp, humidity):
next_temp = coef_temp * temp + coef_humidity * humidity + intercept
return next_temp
def classify_weather(temp, humidity):
if temp > 25 and humidity < 60:
return "Sunny"
elif humidity > 80:
return "Rainy"
else:
return "Cloudy"
connect_wifi('********', 'xucgkudwetr,.')
api_key = '*************'
city = 'your_city'
while True:
temp, humidity = get_weather(api_key, city)
next_temp = predict_next_hour(temp, humidity)
weather = classify_weather(next_temp, humidity)
print(f"Current Temp: {temp}°C, Humidity: {humidity}%")
print(f"Predicted Next Hour Temp: {next_temp}°C")
print(f"Predicted Weather: {weather}")
time.sleep(3600)