import machine
import urequests
import time
import wifi
# Replace with your Wi-Fi credentials
WIFI_SSID = "uaifai"
WIFI_PASSWORD = "73988927035"
# Replace with your ThingSpeak API key
THINGSPEAK_API_KEY = "QOOENPBYZNDL5PT5"
# Function to connect to Wi-Fi
def connect_wifi():
wifi.connect(WIFI_SSID, WIFI_PASSWORD)
while wifi.status() < 3:
pass
# Function to send data to ThingSpeak
def send_to_thingspeak(temp, water, food):
url = "https://api.thingspeak.com/update?api_key=" + THINGSPEAK_API_KEY + "&field1=" + str(temp) + "&field2=" + str(water) + "&field3=" + str(food)
response = urequests.get(url)
response.close()
# Main loop
while True:
# Read sensor data (replace with your actual sensor reading code)
temp = pot1.read()
water = pot2.read()
food = pot3.read()
# Connect to Wi-Fi
connect_wifi()
# Send data to ThingSpeak
send_to_thingspeak(temp, water, food)
time.sleep(15) # Adjust the delay as needed