From 9e0b45acfb796e45fee7f5e9c91c669c35e17390 Mon Sep 17 00:00:00 2001 From: Daniel Svitan Date: Sat, 17 May 2025 22:10:47 +0200 Subject: [PATCH] :fire: Removes debugging control code --- peripheral/main.py | 58 +++++++--------------------------------------- 1 file changed, 9 insertions(+), 49 deletions(-) diff --git a/peripheral/main.py b/peripheral/main.py index 22d628f..1d2e0d9 100644 --- a/peripheral/main.py +++ b/peripheral/main.py @@ -5,43 +5,14 @@ import urequests import machine from machine import Pin -control_button = Pin(16, Pin.IN) led = Pin(15, Pin.OUT) - trigger = Pin(2, Pin.OUT) echo = Pin(3, Pin.IN) sound = 340 * 100 # m/s * centi = cm/s threshold = 15 # cm -exit_standby_counter = 0 -exit_standby_threshold = 3 - -# start in standby mode, break if user holds button for 3s -print("Starting in standby mode...") -while True: - if control_button.value(): - exit_standby_counter += 1 - else: - exit_standby_counter = 0 - - if exit_standby_counter >= exit_standby_threshold: - break - - led.toggle() - utime.sleep_ms(1000) - - -def show_ok(): - led.low() - for _ in range(10): - led.toggle() - utime.sleep_ms(100) - led.low() - - print("Starting door alarm...") -show_ok() ssid = "HUAWEI-2EEt-2G" password = "hxtU2dvx" @@ -52,6 +23,7 @@ ultra_counter = 0 ultra_threshold = 3 # opened state from previous iteration previous_opened = False +# TODO: add if open for more than 1 minute, send alert def connect(): @@ -81,8 +53,6 @@ def connect(): utime.sleep_ms(50) print(f"Connected with IP {wlan.ifconfig()[0]}") - show_ok() - # update server to default value send_req(False) @@ -92,9 +62,12 @@ def send_req(opened: bool): data = {"opened": opened} raw = ujson.dumps(data) - r = urequests.post(f"{server}/write", - headers={"Authorization": token, "Content-Type": "application/json"}, - data=raw) + try: + r = urequests.post(f"{server}/write", + headers={"Authorization": token, "Content-Type": "application/json"}, + data=raw) + except Exception as e: + print(f"Error occurred: {e}") print(f"State updated [{r.status_code}]") @@ -142,12 +115,11 @@ def ultra(): connect() i = 0 -exit_counter = 0 -exit_threshold = 6 +# T = 500ms f = 2 Hz while True: ultra() - if i == 6: + if i == 20: # every 10 seconds, blink for 100ms led.toggle() utime.sleep_ms(100) led.toggle() @@ -157,15 +129,3 @@ while True: utime.sleep_ms(500) i += 1 - - if control_button.value(): - exit_counter += 1 - else: - exit_counter = 0 - if exit_counter >= exit_threshold: - print("Entering glide mode...") - break - -while True: - led.toggle() - utime.sleep_ms(1000)