From 5f0510aec1bebb92713ab49c1e1b8a6d8bac409a Mon Sep 17 00:00:00 2001 From: Arghya Biswas Date: Fri, 26 Sep 2025 15:06:34 +0530 Subject: [PATCH] fix the issue of motor on when the water is 90 Signed-off-by: Arghya Biswas --- Scripts/Main.py | 24 ++++++++++++------------ Scripts/Utility.py | 2 +- config.yaml | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Scripts/Main.py b/Scripts/Main.py index f064449..12d9c5c 100644 --- a/Scripts/Main.py +++ b/Scripts/Main.py @@ -205,20 +205,22 @@ def main(): # Original motor logic if currentTime - lastCheckTime >= CHECK_INTERVAL_SECONDS: - distance = readDistance(gpio, ULTRASONIC_TRIG, ULTRASONIC_ECHO) - if distanceIsValid(distance, lastDistance): - print(f"Distance: {distance} cm") - lastDistance = distance - else: - print(f"Invalid distance reading: {distance} cm; SKIP;") - time.sleep(0.5) - continue + while True: + distance = readDistance(gpio, ULTRASONIC_TRIG, ULTRASONIC_ECHO) + if distanceIsValid(distance, lastDistance): + print(f"Distance: {distance} cm") + lastDistance = distance + break + else: + print(f"Invalid distance reading: {distance} cm; SKIP;") + time.sleep(0.5) + waterLevel = TANK_HEIGHT - distance motorStatus = rtDb.get("motorStatus", "OFF") if configUpdateAvailable: - # Apply config from rtDb.json + # Apply config from rtDb.json both for Manual and Auto modes if motorStatus == "ON": gpio.output(MOTOR_PIN, True) print(f"{currentMode} mode - Config update: Motor ON") @@ -260,9 +262,7 @@ def main(): motorStatus = "ON" print("Auto mode - Tank empty: Motor ON") else: - gpio.output(MOTOR_PIN, False) - motorStatus = "OFF" - print("Auto mode - Tank level OK: Motor OFF") + print(f"Auto mode - Tank level OK: No Motor Update; Currently Motor {motorStatus}") else: print(f"Unknown mode '{currentMode}', defaulting to Auto mode behavior") writeRtDb(mode = "Auto") diff --git a/Scripts/Utility.py b/Scripts/Utility.py index cdce016..ec66978 100644 --- a/Scripts/Utility.py +++ b/Scripts/Utility.py @@ -52,7 +52,7 @@ def ifWaterLevelAboveMax(waterLevel): def ifWaterLevelBelowMin(waterLevel): # Allow a margin of +/- 5 cm around BOTTOM_FULL_DISTANCE for consistency (hysteresis) margin = 5 - minLevel = TANK_HEIGHT - BOTTOM_FULL_DISTANCE + minLevel = BOTTOM_FULL_DISTANCE if waterLevel < (minLevel - margin): return True elif waterLevel > (minLevel + margin): diff --git a/config.yaml b/config.yaml index 1bd3f94..1b27551 100644 --- a/config.yaml +++ b/config.yaml @@ -1,2 +1,2 @@ -appVersion: 1.3.1.1008 +appVersion: 1.3.2.1009