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)