DHT22 included
This commit is contained in:
parent
a3e3da1297
commit
9388f765f4
@ -1,38 +1,38 @@
|
|||||||
from picamera import PiCamera
|
#from picamera import PiCamera
|
||||||
|
import adafruit_dht
|
||||||
|
import board
|
||||||
|
import json
|
||||||
|
|
||||||
class RaspySensors:
|
class RaspySensors:
|
||||||
'''Class to handle all sensors'''
|
'''Class to handle all sensors'''
|
||||||
#Air Temp&Humidity
|
def __init__(self) -> None:
|
||||||
dht22 = 0
|
'''Init all Sensors'''
|
||||||
|
#Message if Error
|
||||||
|
#Air Temperature & Humidity
|
||||||
|
self.dht22 = adafruit_dht.DHT22(board.D4, use_pulseio=False)
|
||||||
|
|
||||||
#Earth Humidity
|
#global Variables
|
||||||
|
self.sensorData ={
|
||||||
|
|
||||||
#Brightness Sensor
|
|
||||||
|
|
||||||
|
|
||||||
#PiCamera
|
|
||||||
camera = PiCamera()
|
|
||||||
|
|
||||||
#GPS
|
|
||||||
|
|
||||||
#Varaibles
|
|
||||||
sensorData ={
|
|
||||||
"Air Temperature" : 0,
|
"Air Temperature" : 0,
|
||||||
"Air Humidity" : 0,
|
"Air Humidity" : 0,
|
||||||
"Earth Humidity" : 0,
|
"Earth Humidity" : 0,
|
||||||
"Brightness" : 0
|
"Brightness" : 0
|
||||||
}
|
}
|
||||||
image = 0
|
|
||||||
position = 0
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
'''Init all Sensors
|
|
||||||
#Message if Error'''
|
|
||||||
dht22 = adafruit_dht.DHT22(board.D4, use_pulseio=False)
|
|
||||||
|
|
||||||
def readSensors(self):
|
def readSensors(self):
|
||||||
'''Read all Sensors and return Dictionary with data'''
|
'''Read all Sensors and return Dictionary with data'''
|
||||||
|
|
||||||
|
#read DHT22
|
||||||
|
#if Error reading Data try again
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
self.sensorData["Air Temperature"] = self.dht22.temperature
|
||||||
|
self.sensorData["Air Humidity"] = self.dht22.humidity
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
return self.sensorData
|
return self.sensorData
|
||||||
|
|
||||||
def takePicture(self):
|
def takePicture(self):
|
||||||
@ -42,3 +42,13 @@ class RaspySensors:
|
|||||||
def readPosition(self):
|
def readPosition(self):
|
||||||
'''Read and return Position'''
|
'''Read and return Position'''
|
||||||
return self.position
|
return self.position
|
||||||
|
|
||||||
|
|
||||||
|
#for Testing only
|
||||||
|
def main():
|
||||||
|
sensors = RaspySensors()
|
||||||
|
test = sensors.readSensors()
|
||||||
|
print("Data:" + json.dumps(test))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
x
Reference in New Issue
Block a user