Bug fixes, drive_all started

This commit is contained in:
Luis Waldhauser 2023-05-15 11:18:48 +02:00
parent b70d445480
commit a0c7bc9077
4 changed files with 29 additions and 4 deletions

View File

@ -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",

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

View File

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