Removed stuff from the try block so it doesn't loop. just initialize in the beginning

This commit is contained in:
Aaron 2025-11-09 01:18:16 -05:00
parent 749eb956a5
commit 24b53b9446

16
main.py
View File

@ -3,10 +3,10 @@ import time # type: ignore
import network # type: ignore import network # type: ignore
import json import json
import gc # type: ignore # ADD THIS - for garbage collection import gc # type: ignore # ADD THIS - for garbage collection
import sys
# Enable watchdog (8 seconds timeout - auto-reboot if frozen) import socket # type: ignore
# wdt = WDT(timeout=8000) # Maximum is 8388ms, use 8000ms (8 seconds) import struct # type: ignore
# print("Watchdog enabled (8s timeout)") import ntptime # type: ignore
# Initialize pins (LED light onboard) # Initialize pins (LED light onboard)
led = Pin("LED", Pin.OUT) led = Pin("LED", Pin.OUT)
@ -158,13 +158,6 @@ if wifi and wifi.isconnected():
# Attempt time sync with timeout (MicroPython compatible) # Attempt time sync with timeout (MicroPython compatible)
ntp_synced = False ntp_synced = False
try: try:
import ntptime # type: ignore
import socket
import struct
# Monkey-patch ntptime.time() to add timeout
original_time_func = ntptime.time
def time_with_timeout(): def time_with_timeout():
"""NTP time fetch with 3-second timeout.""" """NTP time fetch with 3-second timeout."""
NTP_DELTA = 2208988800 NTP_DELTA = 2208988800
@ -344,7 +337,6 @@ print("Press Ctrl+C to stop\n")
retry_ntp_attempts = 0 retry_ntp_attempts = 0
max_ntp_attempts = 5 # Try up to 5 times after initial failure max_ntp_attempts = 5 # Try up to 5 times after initial failure
# ===== START: Main Loop ===== # ===== START: Main Loop =====
# Main monitoring loop (runs forever until Ctrl+C) # Main monitoring loop (runs forever until Ctrl+C)
while True: while True: