From d28ff065f57c1f4a9f8c84448c3834c396c8db9f Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Sun, 6 Sep 2026 01:21:59 -0400 Subject: [PATCH] Adding short delay and LED indicator to show that the app is running --- main.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 1b63709..b774e73 100644 --- a/main.py +++ b/main.py @@ -259,7 +259,7 @@ def register_ha_discovery(mqtt): # ------------------------------------------------------------- -# Main Execution Loop +# Instantiate Wi-Fi connection # ------------------------------------------------------------- def connect_wifi(): wlan = network.WLAN(network.STA_IF) @@ -277,6 +277,21 @@ def connect_wifi(): print(f"Wi-Fi connected. IP: {wlan.ifconfig()[0]}") +# ------------------------------------------------------------- +# Panic when the sensor isn't ready +# ------------------------------------------------------------- +def panic(err=None): + """Signals a fatal fault by blinking the onboard LED continuously.""" + if err: + print(f"Fatal error: {err}") + led = Pin("LED", Pin.OUT) + while True: + led.toggle() + time.sleep(0.1) + +# ------------------------------------------------------------- +# Main Execution Loop +# ------------------------------------------------------------- def main(): # Adjust SDA/SCL pins according to your wiring i2c = SoftI2C(sda=Pin(16), scl=Pin(17), freq=100000) @@ -322,4 +337,13 @@ def main(): if __name__ == "__main__": - main() + # Allow 3.3V power rails and I2C registers to settle on cold boot + time.sleep(2) + + # Indicate startup has begun + Pin("LED", Pin.OUT).on() + + try: + main() + except Exception as e: + panic(e)