|
|
@@ -21,7 +21,6 @@ def measure_send_data(plantID, actionID, client: mqtt.Client): |
|
|
|
sensorData = Sensors.readSensors() |
|
|
|
except Exception as e: |
|
|
|
logging.error(str(e)) |
|
|
|
# TODO Error message MQTT |
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1) |
|
|
|
|
|
|
|
sensorData["PlantID"] = plantID |
|
|
@@ -48,7 +47,6 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client): |
|
|
|
logging.error(f"Robot Error {errorCode} occurred") |
|
|
|
logging.info("Drive Plant aborted, Robot at starting position") |
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], "Drive Plant aborted, Robot at starting position", qos=1) |
|
|
|
#TODO decide about robot occupied message |
|
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
|
|
|
|
|
return |
|
|
@@ -56,6 +54,9 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client): |
|
|
|
logging.info("Measuring Sensors") |
|
|
|
measure_send_data(plantID, actionID, client) |
|
|
|
|
|
|
|
# FIXME Send Picture |
|
|
|
# sendPicture() |
|
|
|
|
|
|
|
logging.info("Robot driving home") |
|
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back.py {plantID}') |
|
|
|
|
|
|
@@ -63,25 +64,24 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client): |
|
|
|
logging.error(f"Robot Error {errorCode} occurred") |
|
|
|
logging.info(f"Drive Home aborted, Robot at plant {plantID}") |
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], f"Drive Home aborted, Robot at plant {plantID}", qos=1) |
|
|
|
#TODO decide about robot occupied message |
|
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
|
return |
|
|
|
|
|
|
|
logging.info("Robot home") |
|
|
|
|
|
|
|
#TODO decide about robot occupied message |
|
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
|
|
|
|
|
|
|
|
|
#region MQTT callbacks |
|
|
|
|
|
|
|
# TODO Test with all sensors |
|
|
|
def drive_plant(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
|
""" |
|
|
|
Function to drive to plant according to request |
|
|
|
Starting Drive in Thread to not block main programm |
|
|
|
|
|
|
|
Args: |
|
|
|
clients (mqtt.Client): current mqtt client |
|
|
|
client (mqtt.Client): current mqtt client |
|
|
|
userdata (_type_): _description_ |
|
|
|
message (mqtt.MQTTMessage): received DRIVE message with PlantID and ActionID |
|
|
|
""" |
|
|
@@ -93,8 +93,6 @@ def drive_plant(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
|
actionID = dictMessage["ActionID"] |
|
|
|
|
|
|
|
logging.info(f"Received Drive-request to plant {plantID}, ActionID: {actionID}") |
|
|
|
|
|
|
|
#TODO decide about robot occupied message |
|
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "False", qos=1) |
|
|
|
|
|
|
|
thread = threading.Thread(target= drive_plant_thread, args=(plantID, actionID, client), daemon=True) |
|
|
@@ -107,7 +105,7 @@ def get_position(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
|
Function to send actual GPS position via MQTT in form of POSITION |
|
|
|
|
|
|
|
Args: |
|
|
|
clients (mqtt.Client): current mqtt client |
|
|
|
client (mqtt.Client): current mqtt client |
|
|
|
userdata (_type_): _description_ |
|
|
|
message (mqtt.MQTTMessage): received message |
|
|
|
""" |
|
|
@@ -129,7 +127,7 @@ def get_BatteryStatus(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
|
5V -> 0% |
|
|
|
|
|
|
|
Args: |
|
|
|
clients (mqtt.Client): current mqtt client |
|
|
|
client (mqtt.Client): current mqtt client |
|
|
|
userdata (_type_): _description_ |
|
|
|
message (mqtt.MQTTMessage): received message |
|
|
|
""" |
|
|
@@ -151,4 +149,25 @@ def get_BatteryStatus(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
|
} |
|
|
|
client.publish(Topics["ROBOT_DATA_BATTERY"], json.dumps(battery, indent=4), qos=1) |
|
|
|
|
|
|
|
# TODO Test needed |
|
|
|
def sendPicture(client: mqtt.Client): |
|
|
|
""" |
|
|
|
Takes picture and publish via MQTT |
|
|
|
|
|
|
|
Args: |
|
|
|
client (mqtt.Client): current mqtt client |
|
|
|
""" |
|
|
|
try: |
|
|
|
Sensors.takePicture() |
|
|
|
except Exception as e: |
|
|
|
logging.error(str(e)) |
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1) |
|
|
|
|
|
|
|
with open("picture.txt", "rb") as f: |
|
|
|
file = f.read() |
|
|
|
byteArr = bytearray(file) |
|
|
|
print(byteArr) |
|
|
|
client.publish(Topics["ROBOT_DATA_IMAGE"], byteArr) |
|
|
|
print("Published") |
|
|
|
|
|
|
|
#endregion |