-
Notifications
You must be signed in to change notification settings - Fork 0
fix the issue of motor on when the water is 90 #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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}") | ||||||||
|
||||||||
| print(f"Auto mode - Tank level OK: No Motor Update; Currently Motor {motorStatus}") | |
| print(f"Auto mode - Tank level OK: No Motor Update; Currently Motor {motorStatus}") | |
| writeRtDb(motorStatus=motorStatus) |
Copilot
AI
Sep 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of the motor OFF logic in lines 262-265 creates incomplete control flow. When the tank level is OK in auto mode, there's no logic to turn the motor OFF, which could lead to overflow conditions.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| appVersion: 1.3.1.1008 | ||
| appVersion: 1.3.2.1009 | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The infinite while loop has no timeout mechanism. If the sensor consistently returns invalid readings, this will block the main thread indefinitely. Add a maximum retry counter or timeout to prevent infinite loops.