actionID (_type_): current ID of driving action | actionID (_type_): current ID of driving action | ||||
client (mqtt.Client): current mqtt client for publishing | client (mqtt.Client): current mqtt client for publishing | ||||
""" | """ | ||||
sensordata = {} | |||||
sensordata |= SENSORDATA | |||||
sensorData = {} | |||||
sensorData |= SENSORDATA | |||||
try: | try: | ||||
sensorData = Sensors.readSensors() | |||||
Sensors.readSensors(sensorData) | |||||
except Exception as e: | except Exception as e: | ||||
logging.error(str(e)) | logging.error(str(e)) | ||||
client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1) | client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1) | ||||
try: | try: | ||||
sensordata = {} | sensordata = {} | ||||
sensordata |= SENSORDATA | sensordata |= SENSORDATA | ||||
sensordata = Sensors.readSensors() | |||||
sensordata["PlantID"] = plant | |||||
allPlantData["SensorData"].append(sensordata) | |||||
Sensors.readSensors(sensordata) | |||||
except Exception as e: | except Exception as e: | ||||
logging.error(str(e)) | logging.error(str(e)) | ||||
client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1) | client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1) | ||||
time.sleep(3) | |||||
sensordata["PlantID"] = plant | |||||
allPlantData["SensorData"].append(sensordata) | |||||
# TODO How to Handle Pictures and PlantID | # TODO How to Handle Pictures and PlantID | ||||
logging.info("Taking Picture") | logging.info("Taking Picture") |
import functions | import functions | ||||
import logging | import logging | ||||
import sys | import sys | ||||
from defines import Topics, RASPI_CLIENT_ID, MQTT_BROKER_GLOBAL | |||||
from defines import Topics, RASPI_CLIENT_ID, MQTT_BROKER_GLOBAL, MQTT_BROKER_LOCAL | |||||
def on_connect(client: mqtt.Client, userdata, flags, rc): | def on_connect(client: mqtt.Client, userdata, flags, rc): | ||||
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout)) | logging.getLogger().addHandler(logging.StreamHandler(sys.stdout)) | ||||
client = mqtt.Client(RASPI_CLIENT_ID) | client = mqtt.Client(RASPI_CLIENT_ID) | ||||
# client = mqtt.Client(RASPI_CLIENT_ID, transport="websockets") # Local Broker | |||||
client.on_connect = on_connect | client.on_connect = on_connect | ||||
client.connect(MQTT_BROKER_GLOBAL) | client.connect(MQTT_BROKER_GLOBAL) | ||||
# client.connect("192.168.137.197") # Local Broker | |||||
# CHECK forever or start | # CHECK forever or start | ||||
client.loop_start() | client.loop_start() |
import adafruit_dht | import adafruit_dht | ||||
import adafruit_tsl2561 | import adafruit_tsl2561 | ||||
import board | import board | ||||
import json | |||||
import spidev | import spidev | ||||
from picamera import PiCamera | from picamera import PiCamera | ||||
from defines import SENSORDATA | from defines import SENSORDATA | ||||
return percentage | return percentage | ||||
# TODO Function for all sensors | # TODO Function for all sensors | ||||
def readSensors(): | |||||
def readSensors(sensorData): | |||||
""" | """ | ||||
Read DHT22, TSL2561 and Humidity Sensor | Read DHT22, TSL2561 and Humidity Sensor | ||||
Args: | |||||
sensorData (dictionary): Dictionary of type SENSORDATA | |||||
Raises: | Raises: | ||||
Exception: DHT22 not connected | Exception: DHT22 not connected | ||||
Exception: TSL2561 not connected | Exception: TSL2561 not connected | ||||
Exception: YL69 not connected | Exception: YL69 not connected | ||||
Returns: | |||||
dict: Sensordata | |||||
""" | """ | ||||
sensorData = {} | |||||
sensorData |= SENSORDATA | |||||
errorMessage = "" | errorMessage = "" | ||||
# read DHT22 | # read DHT22 | ||||
sensorData["SoilMoisture"] = 0 | sensorData["SoilMoisture"] = 0 | ||||
errorMessage = errorMessage + str(e) + "\n" | errorMessage = errorMessage + str(e) + "\n" | ||||
# combined error message | |||||
# combined error message | |||||
if errorMessage != "": | if errorMessage != "": | ||||
raise Exception(errorMessage) | raise Exception(errorMessage) | ||||
return sensorData | |||||
def takePicture(): | def takePicture(): |