Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Scripts/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +208 to +216
Copy link

Copilot AI Sep 26, 2025

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.

Copilot uses AI. Check for mistakes.

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")
Expand Down Expand Up @@ -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}")
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motor status is not being updated in the database when the tank level is OK. This could lead to inconsistent state between the actual motor control logic and the stored motor status. Consider calling writeRtDb(motorStatus=motorStatus) to maintain consistency.

Suggested change
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 uses AI. Check for mistakes.
else:
print(f"Unknown mode '{currentMode}', defaulting to Auto mode behavior")
writeRtDb(mode = "Auto")
Comment on lines 266 to 268
Copy link

Copilot AI Sep 26, 2025

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.

Copilot uses AI. Check for mistakes.
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
appVersion: 1.3.1.1008
appVersion: 1.3.2.1009