1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #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'''
- #[ ]TODO 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,
- "Plant ID": 0,
- "Action ID": 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
-
- #[ ]TODO - take picture function
- def takePicture(self):
- '''Take picture and return image'''
- return self.image
-
- #[ ]TODO
- def readPosition(self):
- '''Read and return Position'''
- return self.position
-
- #[ ]TODO
- def readBattery(self):
- '''Read and return battery of ev3'''
- return self.battery
-
-
-
- #for Testing only
- def main():
- sensors = RaspySensors()
- test = sensors.readSensors()
- print("Data:" + json.dumps(test))
-
- if __name__ == "__main__":
- main()
|