123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #from picamera import PiCamera
- import adafruit_dht
- import board
- import json
-
- class RaspySensors:
- '''Class to handle all sensors'''
- def __init__(self) -> None:
- '''Init all Sensors'''
- #Message if Error
- #Air Temperature & Humidity
- self.dht22 = adafruit_dht.DHT22(board.D4, use_pulseio=False)
-
- #global Variables
- self.sensorData ={
- "Air Temperature" : 0,
- "Air Humidity" : 0,
- "Earth Humidity" : 0,
- "Brightness" : 0
- }
-
- def readSensors(self):
- '''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
-
- def takePicture(self):
- '''Take picture and return image'''
- return self.image
-
- def readPosition(self):
- '''Read and return Position'''
- return self.position
-
-
- #for Testing only
- def main():
- sensors = RaspySensors()
- test = sensors.readSensors()
- print("Data:" + json.dumps(test))
-
- if __name__ == "__main__":
- main()
|