|
|
|
|
|
|
|
|
logging.info("Measuring Sensors") |
|
|
logging.info("Measuring Sensors") |
|
|
measure_send_data(plantID, actionID, client) |
|
|
measure_send_data(plantID, actionID, client) |
|
|
|
|
|
|
|
|
# FIXME Send Picture |
|
|
|
|
|
# sendPicture() |
|
|
|
|
|
|
|
|
logging.info("Taking Picture") |
|
|
|
|
|
sendPicture(client) |
|
|
|
|
|
|
|
|
logging.info("Robot driving home") |
|
|
logging.info("Robot driving home") |
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back.py {plantID}') |
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back.py {plantID}') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region MQTT callbacks |
|
|
#region MQTT callbacks |
|
|
|
|
|
|
|
|
# TODO Test with all sensors |
|
|
|
|
|
def drive_plant(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
def drive_plant(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
""" |
|
|
""" |
|
|
Function to drive to plant according to request |
|
|
Function to drive to plant according to request |
|
|
|
|
|
|
|
|
""" |
|
|
""" |
|
|
dictMessage = json.loads(str(message.payload.decode("UTF-8"))) |
|
|
dictMessage = json.loads(str(message.payload.decode("UTF-8"))) |
|
|
|
|
|
|
|
|
print(dictMessage) |
|
|
|
|
|
|
|
|
|
|
|
plantID = dictMessage["PlantID"] |
|
|
plantID = dictMessage["PlantID"] |
|
|
actionID = dictMessage["ActionID"] |
|
|
actionID = dictMessage["ActionID"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"Battery": batteryLevel |
|
|
"Battery": batteryLevel |
|
|
} |
|
|
} |
|
|
client.publish(Topics["ROBOT_DATA_BATTERY"], json.dumps(battery, indent=4), qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_BATTERY"], json.dumps(battery, indent=4), qos=1) |
|
|
|
|
|
logging.info(f"Battery done {batteryLevel}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO Test needed |
|
|
|
|
|
def sendPicture(client: mqtt.Client): |
|
|
def sendPicture(client: mqtt.Client): |
|
|
""" |
|
|
""" |
|
|
Takes picture and publish via MQTT |
|
|
Takes picture and publish via MQTT |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
with open("picture.txt", "rb") as f: |
|
|
|
|
|
|
|
|
with open("picture.png", "rb") as f: |
|
|
file = f.read() |
|
|
file = f.read() |
|
|
byteArr = bytearray(file) |
|
|
byteArr = bytearray(file) |
|
|
print(byteArr) |
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_IMAGE"], byteArr) |
|
|
|
|
|
print("Published") |
|
|
|
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_PICTURE"], byteArr) |
|
|
|
|
|
logging.info("Picture Published") |
|
|
|
|
|
|
|
|
#endregion |
|
|
#endregion |