|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
dht22 = 0 |
|
|
|
|
|
|
|
|
|
|
|
#Earth Humidity |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Brightness Sensor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#PiCamera |
|
|
|
|
|
camera = PiCamera() |
|
|
|
|
|
|
|
|
|
|
|
#GPS |
|
|
|
|
|
|
|
|
|
|
|
#Varaibles |
|
|
|
|
|
sensorData ={ |
|
|
|
|
|
"Air Temperature" : 0, |
|
|
|
|
|
"Air Humidity" : 0, |
|
|
|
|
|
"Earth Humidity" : 0, |
|
|
|
|
|
"Brightness" : 0 |
|
|
|
|
|
} |
|
|
|
|
|
image = 0 |
|
|
|
|
|
position = 0 |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self) -> None: |
|
|
def __init__(self) -> None: |
|
|
'''Init all Sensors |
|
|
|
|
|
#Message if Error''' |
|
|
|
|
|
dht22 = adafruit_dht.DHT22(board.D4, use_pulseio=False) |
|
|
|
|
|
|
|
|
'''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): |
|
|
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): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() |