From 09c6e5c7861b78926ee367045ffd5a24f302bda8 Mon Sep 17 00:00:00 2001 From: jerick Date: Mon, 28 Nov 2022 16:11:53 -0500 Subject: [PATCH] Fixed pin clearing --- mqtt/tempSensor.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mqtt/tempSensor.py b/mqtt/tempSensor.py index 8fa64ca..3ad2836 100644 --- a/mqtt/tempSensor.py +++ b/mqtt/tempSensor.py @@ -16,6 +16,11 @@ password = 'falrenforbreakfast' client_id = f'python-mqtt-office-{random.randint(0, 1000)}' +#We first check if a libgpiod process is running. If yes, we kill it! +for proc in psutil.process_iter(): + if proc.name() == 'libgpiod_pulsein' or proc.name() == 'libgpiod_pulsei': + proc.kill() + #D20 is the pin number, DHT11 is the sensor type sensor = adafruit_dht.DHT11(board.D20) @@ -89,14 +94,11 @@ def publish(client, temp, humidity): time.sleep(5.0) -# We first check if a libgpiod process is running. If yes, we kill it! -# for proc in psutil.process_iter(): -# if proc.name() == 'libgpiod_pulsein' or proc.name() == 'libgpiod_pulsei': -# proc.kill() -#time.sleep(1.0) + client = connect_mqtt() client.loop_start() print (sensor) - -temp, humidity = getValues(sensor) -publish(client, temp, humidity) +while True: + temp, humidity = getValues(sensor) + publish(client, temp, humidity) + time.sleep (5.0)