def measureMoisture(): pump = SETTINGS["PUMP"] try: average = MCP3008.readMoisture(pi) except: average = 0 if average > 0: average = round(average, 2) wateringTime = round(average / pump["WATERING_FACTOR"], 2) if wateringTime < pump["MIN_WATER"]: print("Watering time, {}, too low. Use minimum watering time: {}". format(wateringTime, pump["MIN_WATER"])) wateringTime = pump["MIN_WATER"] else: wateringTime = pump["WATERING_TIME"] print("Failed to get moisture reading, use default watering time {}". format(wateringTime)) for sensor in SETTINGS["SENSORS"]: utils.blinkLed(pi, sensor["LED"], 20, 0.2) # turn pump on for some seconds print("{}: moisture: {} - turn pump on for {} seconds".format( timestamp, average, wateringTime)) pi.set_mode(pump["LED_GPIO"], pigpio.OUTPUT) pi.set_mode(pump["GPIO"], pigpio.OUTPUT) pi.write(pump["LED_GPIO"], 1) pi.write(pump["GPIO"], 0) time.sleep(wateringTime) pi.write(pump["GPIO"], 1) pi.write(pump["LED_GPIO"], 0)
def measureMoisture(): try: average = MCP3008.readMoisture(pi) except: average = 0 if average == 0: utils.turnOffLeds(pi) print("Failed to get moisture reading!\n") return "not read" return average