Created
May 13, 2025 09:42
-
-
Save benevpi/65c8891e5da63879459e1a2d9c667a14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import machine | |
import time | |
import network | |
import socket | |
import urequests as requests | |
import json | |
ssid = 'YOUR_WIFI_SSID' | |
password = 'YOUR_WIFI_PASSWORD' | |
lat = "52.52" | |
long = "13.41" | |
url = "https://api.open-meteo.com/v1/forecast?latitude="+lat+"&longitude="+long+"&daily=precipitation_probability_max&timezone=Europe%2FLondon&forecast_days=1" | |
wlan = network.WLAN(network.STA_IF) | |
wlan.active(True) | |
wlan.connect(ssid, password) | |
while wlan.isconnected() == False: | |
print('Waiting for connection...') | |
time.sleep(1) | |
print(wlan.ifconfig()) | |
pins = [] | |
for i in range(23): | |
pins.append(machine.Pin(i, machine.Pin.OUT)) | |
while True: | |
res = requests.get(url=url) | |
if (float(res.json()['daily']['precipitation_probability_max'][0])) > 0.3: | |
#run for approx one hour | |
for pin in pins: | |
pin.on() | |
else: | |
for pin in pins: | |
pin.off() | |
time.sleep(60*60) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment