#from picamera import PiCamera import adafruit_dht import adafruit_tsl2561 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) #Brightness self.tsl2561 = adafruit_tsl2561.TSL2561(board.I2C()) #global Variables self.sensorData ={ "Air Temperature [°C]" : 0, "Air Humidity [%]" : 0, "Earth Humidity [%]" : 0, "Brightness [Lux]" : 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 [°C]"] = self.dht22.temperature self.sensorData["Air Humidity [%]"] = self.dht22.humidity except: continue break #read TSL2561 self.sensorData["Brightness [Lux]"] = round(self.tsl2561.lux, 2) 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()