|
|
@@ -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: |