Created Temp Test file
This commit is contained in:
23
mqtt/tempTest.py
Normal file
23
mqtt/tempTest.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import time
|
||||
import board
|
||||
import adafruit_dht
|
||||
import psutil
|
||||
import random
|
||||
|
||||
from paho.mqtt import client as mqtt_client
|
||||
|
||||
sensor = adafruit_dht.DHT11(board.D20)
|
||||
|
||||
try:
|
||||
temp = sensor.temperature
|
||||
humidity = sensor.humidity
|
||||
|
||||
#convert to Farenheit
|
||||
temp = (temp * 1.8) + 32
|
||||
print("Temperature: {}*F Humidity: {}% ".format(temp, humidity))
|
||||
except RuntimeError as error:
|
||||
print(error.args[0])
|
||||
time.sleep(2.0)
|
||||
except Exception as error:
|
||||
sensor.exit()
|
||||
raise error
|
||||
Reference in New Issue
Block a user