From 5d7caa24a4020271cf431be932e4db66cc09e2c2 Mon Sep 17 00:00:00 2001 From: Juliana Mashon Date: Thu, 18 Jul 2024 11:08:59 -0700 Subject: [PATCH] Added get_xyz() --- broker_functions.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/broker_functions.py b/broker_functions.py index 0d36bc4..387c3c4 100644 --- a/broker_functions.py +++ b/broker_functions.py @@ -32,7 +32,7 @@ def read_status(self): status_tree = self.broker_connect.last_message - return print(json.dumps(status_tree, indent=4)) + return status_tree def read_sensor(self, id): peripheral_str = self.api.get_info('peripherals', id) @@ -56,12 +56,7 @@ def read_sensor(self, id): }] } - self.broker_connect.publish(read_sensor_message) - self.broker_connect.listen(5, 'status') - - sensor_data = self.broker_connect.last_message - - return print(sensor_data) + # return ... def message(self, message, type=None, channel=None): message_message = { @@ -311,7 +306,20 @@ def detect_weeds(self): self.broker_connect.publish(detect_weeds_message) # return ... - # get_xyz() --> requires read_status() --> LUA + def get_xyz(self): + tree_data = self.read_status() + + position = tree_data["position"] + + x_val = position['x'] + y_val = position['y'] + z_val = position['z'] + + return print(f'Garden size:\n' + f'\tx = {x_val:.2f}\n' + f'\ty = {y_val:.2f}\n' + f'\tz = {z_val:.2f}') + # check_position() --> requires read_status() --> LUA def move(self, x, y, z):