From a5864add5d3d59a751da1d84c5e74ab5eb8df281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Sun, 17 Jul 2022 21:13:59 +0200 Subject: [PATCH] added new methode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 76e02f6..399cde6 100644 --- a/main.py +++ b/main.py @@ -27,16 +27,15 @@ def error_print(message: str): #relay def relay_controller(pin: int, state: str): if state == "True": - os.system('echo "1" > /sys/class/gpio/gpio'+str(pin)+'/value') + os.system('raspi-gpio set '+str(pin)+' op') debug_print("Set relay-pin "+str(pin)+" to state True") elif state == "False": - os.system('echo "0" > /sys/class/gpio/gpio'+str(pin)+'/value') + os.system('raspi-gpio set '+str(pin)+' ip') debug_print("Set relay-pin "+str(pin)+" to state False") else: error_print("Unknown state ("+state+") for relay channel "+str(pin)) #ultrasonic - def get_water_level(): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) @@ -111,11 +110,6 @@ def mqtt_on_message(client, userdata, msg): if __name__ == "__main__": - relay_channels = ["19", "16", "26", "20"] - for channel in relay_channels: - os.system('echo "'+channel+'" /sys/class/gpio/export') - os.system('echo "out" > /sys/class/gpio/gpio'+channel+'/direction') - mqttBroker ="homeassistant.ping-mee.local" client = mqtt.Client("greenhouse_client") client.username_pw_set("mqtt", "pmMQTT_11!") @@ -134,6 +128,7 @@ if __name__ == "__main__": debug_print("Published current water level: "+get_water_level()) time.sleep(1) except KeyboardInterrupt: + relay_channels = ["19", "16", "26", "20"] for channel in relay_channels: - os.system('echo "'+channel+'" > /sys/class/gpio/unexport') + os.system('raspi-gpio set '+channel+' ip') GPIO.cleanup() \ No newline at end of file