Compare commits
2 Commits
5794987ff0
...
faecbb7939
| Author | SHA1 | Date | |
|---|---|---|---|
| faecbb7939 | |||
| 8b08e98fe7 |
@@ -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
24
mqtt/tempSensor.py
Normal 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)
|
||||
Reference in New Issue
Block a user