removed waterlevel temporarly

Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>
master
Ebbe Baß 2022-08-11 23:17:46 +02:00
parent 160b724de5
commit 96a9740e79
1 changed files with 27 additions and 27 deletions

54
main.py
View File

@ -40,35 +40,35 @@ def relay_controller(pin: int, state: str):
error_print("Unknown state ("+state+") for relay channel "+str(pin)) error_print("Unknown state ("+state+") for relay channel "+str(pin))
#ultrasonic #ultrasonic
try: # try:
def get_water_level(): # def get_water_level():
GPIO.setmode(GPIO.BCM) # GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False) # GPIO.setwarnings(False)
GPIO_TRIGGER = 24 # GPIO_TRIGGER = 24
GPIO_ECHO = 25 # GPIO_ECHO = 25
GPIO.setup(GPIO_TRIGGER, GPIO.OUT) # GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN) # GPIO.setup(GPIO_ECHO, GPIO.IN)
GPIO.output(GPIO_TRIGGER, True) # GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001) # time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False) # GPIO.output(GPIO_TRIGGER, False)
startTime = time.time() # startTime = time.time()
StopTime = time.time() # StopTime = time.time()
while GPIO.input(GPIO_ECHO) == 0: # while GPIO.input(GPIO_ECHO) == 0:
startTime = time.time() # startTime = time.time()
while GPIO.input(GPIO_ECHO) == 1: # while GPIO.input(GPIO_ECHO) == 1:
StopTime = time.time() # StopTime = time.time()
TimeElapsed = StopTime - startTime # TimeElapsed = StopTime - startTime
distance = (TimeElapsed * 34300) / 2 # distance = (TimeElapsed * 34300) / 2
rounded_distance = int(distance) # rounded_distance = int(distance)
return str(rounded_distance) # return str(rounded_distance)
print(get_water_level()) # print(get_water_level())
debug_print("Added water level detector") # debug_print("Added water level detector")
except: # except:
print("Adding water level sensor fail.") # print("Adding water level sensor fail.")
#temperature #temperature
try: try:
@ -137,8 +137,8 @@ if __name__ == "__main__":
while True: while True:
client.publish("strawberry-pi-greenhouse/sensor/temperature", get_temperature()) client.publish("strawberry-pi-greenhouse/sensor/temperature", get_temperature())
debug_print("Published current temperature: "+get_temperature()) debug_print("Published current temperature: "+get_temperature())
client.publish("strawberry-pi-greenhouse/sensor/water-level", get_water_level()) # client.publish("strawberry-pi-greenhouse/sensor/water-level", get_water_level())
debug_print("Published current water level: "+get_water_level()) # debug_print("Published current water level: "+get_water_level())
time.sleep(1) time.sleep(1)
except KeyboardInterrupt: except KeyboardInterrupt:
relay_channels = ["19", "16", "26", "20"] relay_channels = ["19", "16", "26", "20"]