Added try/except in sensor adding part
Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>master
parent
3167fff6e6
commit
dee007196b
11
main.py
11
main.py
|
@ -40,6 +40,7 @@ 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:
|
||||||
def get_water_level():
|
def get_water_level():
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.setwarnings(False)
|
GPIO.setwarnings(False)
|
||||||
|
@ -64,9 +65,13 @@ def get_water_level():
|
||||||
rounded_distance = int(distance)
|
rounded_distance = int(distance)
|
||||||
return str(rounded_distance)
|
return str(rounded_distance)
|
||||||
|
|
||||||
|
print(get_water_level())
|
||||||
debug_print("Added water level detector")
|
debug_print("Added water level detector")
|
||||||
|
except:
|
||||||
|
print("Adding water level sensor fail.")
|
||||||
|
|
||||||
#temperature
|
#temperature
|
||||||
|
try:
|
||||||
def get_temperature():
|
def get_temperature():
|
||||||
i2c = busio.I2C(board.SCL, board.SDA)
|
i2c = busio.I2C(board.SCL, board.SDA)
|
||||||
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76)
|
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76)
|
||||||
|
@ -74,11 +79,9 @@ def get_temperature():
|
||||||
return str(rounded_temp)
|
return str(rounded_temp)
|
||||||
|
|
||||||
debug_print("Added temperature sensor")
|
debug_print("Added temperature sensor")
|
||||||
|
|
||||||
print(get_water_level())
|
|
||||||
debug_print("got water level")
|
|
||||||
print(get_temperature())
|
print(get_temperature())
|
||||||
debug_print("got temperature")
|
except:
|
||||||
|
print("Adding temperature sensor faild.")
|
||||||
|
|
||||||
def mqtt_on_connect(client, userdata, flags, rc):
|
def mqtt_on_connect(client, userdata, flags, rc):
|
||||||
client.subscribe("strawberry-pi-greenhouse/relay/channel/1")
|
client.subscribe("strawberry-pi-greenhouse/relay/channel/1")
|
||||||
|
|
Loading…
Reference in New Issue