diff --git a/software/roboter/raspy/defines.py b/software/roboter/raspy/defines.py index 929cf64..59c6989 100644 --- a/software/roboter/raspy/defines.py +++ b/software/roboter/raspy/defines.py @@ -12,6 +12,7 @@ BACKEND_CLIENT_ID = "smart_farming_server" # Topics: Topics = { "ROBOT_ACTION_DRIVE": "ROBOT/ACTION/DRIVE", + "ROBOT_ACTION_DRIVEALL": "ROBOT/ACTION/DRIVEALL", "ROBOT_ACTION_GETPOSITION": "ROBOT/ACTION/GETPOSITION", "ROBOT_ACTION_GETBATTERY": "ROBOT/ACTION/GETBATTERY", diff --git a/software/roboter/raspy/functions.py b/software/roboter/raspy/functions.py index b43382a..a94f86a 100644 --- a/software/roboter/raspy/functions.py +++ b/software/roboter/raspy/functions.py @@ -68,10 +68,19 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client): return logging.info("Robot home") - client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) +# TODO thread all plants +def drive_plant_all(plantID, actionID, client: mqtt.Client): + + # TODO loop through plantID array + + logging.info("Robot home") + client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) + + + #region MQTT callbacks def drive_plant(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): @@ -96,6 +105,21 @@ def drive_plant(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): thread.start() +# TODO Drive all Plants +# TODO plantID array +# TODO only possible with color codes +def drive_plant_all(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): + dictMessage = json.loads(str(message.payload.decode("UTF-8"))) + + plantID = dictMessage["PlantID"] + actionID = dictMessage["ActionID"] + + logging.info(f"Received Drive-request to plants {plantID}, ActionID: {actionID}") + client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "False", qos=1) + + thread = threading.Thread(target= drive_plant_all, args=(plantID, actionID, client), daemon=True) + thread.start() + def get_position(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage): """ Callback function for GPS position request diff --git a/software/roboter/raspy/picture.png b/software/roboter/raspy/picture.png new file mode 100644 index 0000000..2bc9feb Binary files /dev/null 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 42ad204..6867305 100644 --- a/software/roboter/raspy/raspy_sensors.py +++ b/software/roboter/raspy/raspy_sensors.py @@ -81,9 +81,9 @@ def readMCP3008(): val = spi.xfer2([1,(8+channel) << 4, 0]) data = ((val[1] & 3) << 9) +val[2] percentage = data - 680 # Return values between ~1780 and ~680 - percentage = round((1100 - percentage) / 1100, 2) # 680 -> 100% moisture, 1780 -> 0% moisture + percentage = round(((1100 - percentage) / 1100) *100, 2) # 680 -> 100% moisture, 1780 -> 0% moisture - if percentage > 1 or percentage < 0: # If not connected values above 100% appear + if percentage > 100 or percentage < 0: # If not connected values above 100% appear percentage = 0 raise Exception("YL69 not connected") @@ -171,7 +171,7 @@ def readPosition(): def main(): value = SENSORDATA try: - readSensors() + readMCP3008() except Exception as e: print(str(e))