diff --git a/software/roboter/raspy/functions.py b/software/roboter/raspy/functions.py index 1656382..0c03514 100644 --- a/software/roboter/raspy/functions.py +++ b/software/roboter/raspy/functions.py @@ -6,6 +6,8 @@ import logging import raspy_sensors as Sensors from defines import Topics, SENSORDATA, ALLSENSORDATA +import time + def measure_send_data(plantID, actionID, client: mqtt.Client): """ Reads all sensors and publishes data via MQTT in form of SENSORDATA @@ -15,7 +17,8 @@ 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 try: sensorData = Sensors.readSensors() @@ -84,12 +87,15 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client): client (mqtt.Client): current MQTT client """ - allPlantData = ALLSENSORDATA + allPlantData = { + "SensorData": [], + "ActionID": "" + } + allPlantData["ActionID"] = actionID - logging.debug(f"plants {plantIDs}, type {type(plantIDs)}") for plant in plantIDs: - # FIXME Only possible with color codes + # FIXME Only possible with color codes logging.info(f"Robot Driving to plant {plant}") errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plant}') if errorCode != 0: @@ -103,10 +109,16 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client): # TODO Test error handling logging.info("Measuring Sensors") try: - allPlantData["PlantData"].append(Sensors.readSensors()) + sensordata = {} + sensordata |= SENSORDATA + sensordata = Sensors.readSensors() + sensordata["PlantID"] = plant + allPlantData["SensorData"].append(sensordata) except Exception as e: logging.error(str(e)) client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1) + + time.sleep(3) # TODO How to Handle Pictures and PlantID @@ -124,6 +136,7 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client): logging.info("All Plants measured, sending data") client.publish(Topics["ROBOT_DATA_ALL"], json.dumps(allPlantData, indent=4), qos=1) + logging.info("Robot driving home") errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back_straight.py') if errorCode != 0: diff --git a/software/roboter/raspy/picture.png b/software/roboter/raspy/picture.png index 2bc9feb..938f838 100644 Binary files a/software/roboter/raspy/picture.png and b/software/roboter/raspy/picture.png differ diff --git a/software/roboter/raspy/raspy_sensors.py b/software/roboter/raspy/raspy_sensors.py index 6867305..cf8d11f 100644 --- a/software/roboter/raspy/raspy_sensors.py +++ b/software/roboter/raspy/raspy_sensors.py @@ -104,7 +104,8 @@ def readSensors(): Returns: dict: Sensordata """ - sensorData = SENSORDATA + sensorData = {} + sensorData |= SENSORDATA errorMessage = "" # read DHT22 @@ -171,7 +172,7 @@ def readPosition(): def main(): value = SENSORDATA try: - readMCP3008() + value |= readSensors() except Exception as e: print(str(e))