🔥 Removes debugging control code
This commit is contained in:
parent
6e39a82bbb
commit
9e0b45acfb
@ -5,43 +5,14 @@ import urequests
|
|||||||
import machine
|
import machine
|
||||||
from machine import Pin
|
from machine import Pin
|
||||||
|
|
||||||
control_button = Pin(16, Pin.IN)
|
|
||||||
led = Pin(15, Pin.OUT)
|
led = Pin(15, Pin.OUT)
|
||||||
|
|
||||||
trigger = Pin(2, Pin.OUT)
|
trigger = Pin(2, Pin.OUT)
|
||||||
echo = Pin(3, Pin.IN)
|
echo = Pin(3, Pin.IN)
|
||||||
|
|
||||||
sound = 340 * 100 # m/s * centi = cm/s
|
sound = 340 * 100 # m/s * centi = cm/s
|
||||||
threshold = 15 # cm
|
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...")
|
print("Starting door alarm...")
|
||||||
show_ok()
|
|
||||||
|
|
||||||
ssid = "HUAWEI-2EEt-2G"
|
ssid = "HUAWEI-2EEt-2G"
|
||||||
password = "hxtU2dvx"
|
password = "hxtU2dvx"
|
||||||
@ -52,6 +23,7 @@ ultra_counter = 0
|
|||||||
ultra_threshold = 3
|
ultra_threshold = 3
|
||||||
# opened state from previous iteration
|
# opened state from previous iteration
|
||||||
previous_opened = False
|
previous_opened = False
|
||||||
|
# TODO: add if open for more than 1 minute, send alert
|
||||||
|
|
||||||
|
|
||||||
def connect():
|
def connect():
|
||||||
@ -81,8 +53,6 @@ def connect():
|
|||||||
utime.sleep_ms(50)
|
utime.sleep_ms(50)
|
||||||
|
|
||||||
print(f"Connected with IP {wlan.ifconfig()[0]}")
|
print(f"Connected with IP {wlan.ifconfig()[0]}")
|
||||||
show_ok()
|
|
||||||
|
|
||||||
# update server to default value
|
# update server to default value
|
||||||
send_req(False)
|
send_req(False)
|
||||||
|
|
||||||
@ -92,9 +62,12 @@ def send_req(opened: bool):
|
|||||||
|
|
||||||
data = {"opened": opened}
|
data = {"opened": opened}
|
||||||
raw = ujson.dumps(data)
|
raw = ujson.dumps(data)
|
||||||
r = urequests.post(f"{server}/write",
|
try:
|
||||||
headers={"Authorization": token, "Content-Type": "application/json"},
|
r = urequests.post(f"{server}/write",
|
||||||
data=raw)
|
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}]")
|
print(f"State updated [{r.status_code}]")
|
||||||
|
|
||||||
|
|
||||||
@ -142,12 +115,11 @@ def ultra():
|
|||||||
connect()
|
connect()
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
exit_counter = 0
|
# T = 500ms f = 2 Hz
|
||||||
exit_threshold = 6
|
|
||||||
while True:
|
while True:
|
||||||
ultra()
|
ultra()
|
||||||
|
|
||||||
if i == 6:
|
if i == 20: # every 10 seconds, blink for 100ms
|
||||||
led.toggle()
|
led.toggle()
|
||||||
utime.sleep_ms(100)
|
utime.sleep_ms(100)
|
||||||
led.toggle()
|
led.toggle()
|
||||||
@ -157,15 +129,3 @@ while True:
|
|||||||
utime.sleep_ms(500)
|
utime.sleep_ms(500)
|
||||||
|
|
||||||
i += 1
|
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)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user