Includes weather data retrieval from Open-Meteo API and basic WiFi setup for connectivity. IntelliJ project configuration files and a `.gitignore` for IDE-specific files are also added.
45 lines
1.0 KiB
Python
45 lines
1.0 KiB
Python
import network
|
|
import socket
|
|
import time
|
|
import weather_requests
|
|
|
|
|
|
# --- WiFi Connection Setup ---
|
|
SSID = 'octopod' # Replace with your WiFi SSID
|
|
PASSWORD = 'amniotic-duo-portfolio' # Replace with your WiFi Password
|
|
|
|
#Set current location
|
|
latitude = 50.9097
|
|
longitude = -1.4043
|
|
|
|
|
|
station = network.WLAN(network.STA_IF)
|
|
station.active(True)
|
|
station.connect(SSID, PASSWORD)
|
|
print("Connecting to WiFi...")
|
|
|
|
|
|
timeout = 10
|
|
start_time = time.time()
|
|
while not station.isconnected():
|
|
if time.time() - start_time > timeout:
|
|
print("Failed to connect to WiFi. Check your SSID and password.")
|
|
break
|
|
time.sleep(1)
|
|
|
|
if station.isconnected():
|
|
ip = station.ipconfig("addr4")
|
|
time.sleep(1)
|
|
ipv6_addr = station.ipconfig("addr6")
|
|
print("Connected to WiFi! IPv4 address:", ip)
|
|
print("Connected to WiFi! IPv6 address:", ipv6_addr)
|
|
else:
|
|
print("WiFi connection not established. Restart and try again.")
|
|
raise SystemExit
|
|
|
|
|
|
|
|
weather = weather_requests.get_daily(latitude, longitude)
|
|
|
|
print(weather_requests.get_today_forecast(weather))
|