Compare commits

...

2 Commits

Author SHA1 Message Date
faecbb7939 Temp sensor functionality, changed README 2022-11-28 11:18:19 -05:00
8b08e98fe7 Temp Sensor functionality, Changed README 2022-11-28 11:17:59 -05:00
2 changed files with 28 additions and 0 deletions

View File

@@ -1,2 +1,6 @@
Service File can be found at /lib/systemd/system on Pi
DHT11 temp Sensor guide: https://www.freva.com/dht11-temperature-and-humidity-sensor-on-raspberry-pi/

24
mqtt/tempSensor.py Normal file
View File

@@ -0,0 +1,24 @@
import time
import board
import adafruit_dht
import psutil
# 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)
while True:
try:
temp = sensor.temperature
humidity = sensor.humidity
print("Temperature: {}*C Humidity: {}% ".format(temp, humidity))
except RuntimeError as error:
print(error.args[0])
time.sleep(2.0)
continue
except Exception as error:
sensor.exit()
raise error
#time between temp and humidity checks
time.sleep(2.0)