# MicroPython code for IoT project with LED lighting up after 6:30 PM (with time manipulation)
from machine import Pin, RTC
import utime
import network
import time
import urequests # handles making and servicing network requests
print("Connecting to WiFi", end="")
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
# wlan.connect('Om Shree Ganesh05', 'shivaa005')
while not wlan.isconnected():
print(".", end="")
time.sleep(0.1)
print(" Connected!")
print(wlan.ifconfig())
# Simulated components
led_pin = Pin(2, Pin.OUT) # Connect the LED to GPIO 2
rtc = RTC()
# Function to check if it's past 6:30 PM
def is_after_630pm(current_time):
return current_time[3] > 18 or (current_time[3] == 18 and current_time[4] >= 30)
def get_time():
response = urequests.get("http://worldtimeapi.org/api/timezone/Europe/Paris")
data = response.json()
print(data)
timestamp = data["unixtime"]
return timestamp
# Main loop
while True:
current_time = get_time()
print(current_time )
formatted_time = time.localtime(current_time)
# Check if it's past 6:30 PM
if is_after_630pm(formatted_time):
led_pin.value(1) # Turn on the LED
else:
led_pin.value(0) # Turn off the LED
utime.sleep(5) # Check every minute
Loading
pi-pico-w
pi-pico-w