@@ -17,11 +17,11 @@ def measure_send_data(plantID, actionID, client: mqtt.Client): | |||
actionID (_type_): current ID of driving action | |||
client (mqtt.Client): current mqtt client for publishing | |||
""" | |||
sensordata = {} | |||
sensordata |= SENSORDATA | |||
sensorData = {} | |||
sensorData |= SENSORDATA | |||
try: | |||
sensorData = Sensors.readSensors() | |||
Sensors.readSensors(sensorData) | |||
except Exception as e: | |||
logging.error(str(e)) | |||
client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1) | |||
@@ -111,15 +111,14 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client): | |||
try: | |||
sensordata = {} | |||
sensordata |= SENSORDATA | |||
sensordata = Sensors.readSensors() | |||
sensordata["PlantID"] = plant | |||
allPlantData["SensorData"].append(sensordata) | |||
Sensors.readSensors(sensordata) | |||
except Exception as e: | |||
logging.error(str(e)) | |||
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 | |||
logging.info("Taking Picture") |
@@ -12,7 +12,7 @@ import paho.mqtt.client as mqtt | |||
import functions | |||
import logging | |||
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): | |||
@@ -53,8 +53,11 @@ def main(): | |||
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout)) | |||
client = mqtt.Client(RASPI_CLIENT_ID) | |||
# client = mqtt.Client(RASPI_CLIENT_ID, transport="websockets") # Local Broker | |||
client.on_connect = on_connect | |||
client.connect(MQTT_BROKER_GLOBAL) | |||
# client.connect("192.168.137.197") # Local Broker | |||
# CHECK forever or start | |||
client.loop_start() |
@@ -2,7 +2,6 @@ | |||
import adafruit_dht | |||
import adafruit_tsl2561 | |||
import board | |||
import json | |||
import spidev | |||
from picamera import PiCamera | |||
from defines import SENSORDATA | |||
@@ -90,22 +89,19 @@ def readMCP3008(): | |||
return percentage | |||
# TODO Function for all sensors | |||
def readSensors(): | |||
def readSensors(sensorData): | |||
""" | |||
Read DHT22, TSL2561 and Humidity Sensor | |||
Args: | |||
sensorData (dictionary): Dictionary of type SENSORDATA | |||
Raises: | |||
Exception: DHT22 not connected | |||
Exception: TSL2561 not connected | |||
Exception: YL69 not connected | |||
Returns: | |||
dict: Sensordata | |||
""" | |||
sensorData = {} | |||
sensorData |= SENSORDATA | |||
errorMessage = "" | |||
# read DHT22 | |||
@@ -130,11 +126,10 @@ def readSensors(): | |||
sensorData["SoilMoisture"] = 0 | |||
errorMessage = errorMessage + str(e) + "\n" | |||
# combined error message | |||
# combined error message | |||
if errorMessage != "": | |||
raise Exception(errorMessage) | |||
return sensorData | |||
def takePicture(): |