From 6fbc80f8f7197885ad69d074d5d49e1170f0dc83 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 25 Jun 2024 14:40:07 +0200 Subject: [PATCH] Fixed last will message for API Some preparations for new feautures --- CaSSAndRA/app.py | 2 +- CaSSAndRA/src/backend/backendserver.py | 4 +--- CaSSAndRA/src/backend/comm/api.py | 12 ++++-------- CaSSAndRA/src/backend/comm/connections.py | 4 +++- CaSSAndRA/src/backend/data/appdata.py | 2 +- CaSSAndRA/src/backend/data/mapdata.py | 10 +++++++++- CaSSAndRA/src/backend/data/scheduledata.py | 3 +-- CaSSAndRA/src/components/state/buttongroupcontrol.py | 6 ++---- CaSSAndRA/src/components/tasks/buttons.py | 6 ++---- 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/CaSSAndRA/app.py b/CaSSAndRA/app.py index 79fad89..749b23a 100755 --- a/CaSSAndRA/app.py +++ b/CaSSAndRA/app.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -#Version:0.118.0 Add move command to api +#Version:0.119.0 Fixed Last will message in API, some preparations for new feautures # package imports import os import sys diff --git a/CaSSAndRA/src/backend/backendserver.py b/CaSSAndRA/src/backend/backendserver.py index 3dbf1e7..30e687e 100644 --- a/CaSSAndRA/src/backend/backendserver.py +++ b/CaSSAndRA/src/backend/backendserver.py @@ -250,7 +250,6 @@ def start(file_paths) -> None: cfg = cfg = dict(CLIENT_ID=cfgdata.commcfg.api_mqtt_client_id, USERNAME=cfgdata.commcfg.api_mqtt_username, PASSWORD=cfgdata.commcfg.api_mqtt_pass, MQTT_SERVER=cfgdata.commcfg.api_mqtt_server, PORT=cfgdata.commcfg.api_mqtt_port, NAME=cfgdata.commcfg.api_mqtt_cassandra_server_name) mqttapi.create(cfg, topics) - mqttapi.client.will_set(mqttapi.mqtt_mower_name+'/status', payload='offline', retain=True) mqttapi.connect() connection_start = datetime.now() while mqttapi.client.connection_flag != True: @@ -258,13 +257,12 @@ def start(file_paths) -> None: if (datetime.now()-connection_start).seconds >10: break if mqttapi.client.connection_flag: - mqttapi.client.publish(cfgdata.commcfg.api_mqtt_cassandra_server_name+'/status', 'boot') + mqttapi.client.publish(mqttapi.mqtt_mower_name+'/status', 'boot') logger.info('Starting API thread') api_thread = threading.Thread(target=api, args=(restart,), name='api') api_thread.setDaemon(True) api_thread.start() logger.info('API successful created') - if cfgdata.commcfg.message_service != None: if cfgdata.commcfg.message_service == 'Telegram': messageservice.telegram_token = cfgdata.commcfg.telegram_token diff --git a/CaSSAndRA/src/backend/comm/api.py b/CaSSAndRA/src/backend/comm/api.py index 4e6b095..2bd0fff 100644 --- a/CaSSAndRA/src/backend/comm/api.py +++ b/CaSSAndRA/src/backend/comm/api.py @@ -289,8 +289,7 @@ def perform_tasks_cmd(self, buffer: dict) -> None: current_map.calculating = True path.calc_task(current_task.subtasks, current_task.subtasks_parameters) current_map.calculating = False - current_map.mowpath = current_map.preview - current_map.mowpath['type'] = 'way' + current_map.calc_route_mowpath() cmdlist.cmd_take_map = True except Exception as e: logger.info(f'No valid value in api message found. Allowed values: {allowed_values}. Aborting') @@ -347,8 +346,7 @@ def perform_mow_cmd(self) -> None: current_map.calculating = True path.calc_task(current_task.subtasks, current_task.subtasks_parameters) current_map.calculating = False - current_map.mowpath = current_map.preview - current_map.mowpath['type'] = 'way' + current_map.calc_route_mowpath() cmdlist.cmd_mow = True else: logger.info(f'No selected tasks found') @@ -362,8 +360,7 @@ def perform_mow_cmd(self) -> None: current_map.areatomow = round(current_map.selected_perimeter.area) current_map.calc_route_preview(route) current_map.calculating = False - current_map.mowpath = current_map.preview - current_map.mowpath['type'] = 'way' + current_map.calc_route_mowpath() cmdlist.cmd_mow = True elif self.value == 'selection': if 'selection' in self.mapstate: @@ -376,8 +373,7 @@ def perform_mow_cmd(self) -> None: current_map.calc_route_preview(route) current_map.areatomow = round(current_map.selected_perimeter.area) current_map.calculating = False - current_map.mowpath = current_map.preview - current_map.mowpath['type'] = 'way' + current_map.calc_route_mowpath() cmdlist.cmd_mow = True else: logger.info(f'No selection found') diff --git a/CaSSAndRA/src/backend/comm/connections.py b/CaSSAndRA/src/backend/comm/connections.py index cf3f140..929accc 100644 --- a/CaSSAndRA/src/backend/comm/connections.py +++ b/CaSSAndRA/src/backend/comm/connections.py @@ -43,12 +43,14 @@ def create(self, cfg: dict, topics: dict) -> None: def disconnect(self) -> None: logger.info('Disconnecting') + self.client.publish(self.mqtt_mower_name+'/status', 'offline') self.client.disconnect() def connect(self) -> None: self.client.on_connect = self.on_connect self.client.on_disconnect = self.on_disconnect try: + self.client.will_set(f'{self.mqtt_mower_name}/status', payload='offline', qos=0, retain=False) self.client.connect(self.mqtt_server, self.mqtt_port, keepalive=60) logger.info('Connecting...') except Exception as e: @@ -67,7 +69,7 @@ def on_connect(self, client, userdata, flags, rc): client.connection_flag = False def on_disconnect(self, client, userdata, rc): - logger.warning('MQTT connection lost, reconnecting...') + logger.warning('MQTT connection disconnected') logger.info(f"Disconnecting reason: {rc}") self.client.connection_flag = False diff --git a/CaSSAndRA/src/backend/data/appdata.py b/CaSSAndRA/src/backend/data/appdata.py index fc70e03..f0da9b1 100644 --- a/CaSSAndRA/src/backend/data/appdata.py +++ b/CaSSAndRA/src/backend/data/appdata.py @@ -1,4 +1,4 @@ import logging logger = logging.getLogger(__name__) -version = '0.118.0' \ No newline at end of file +version = '0.119.0' \ No newline at end of file diff --git a/CaSSAndRA/src/backend/data/mapdata.py b/CaSSAndRA/src/backend/data/mapdata.py index b8c35cc..b3376e1 100644 --- a/CaSSAndRA/src/backend/data/mapdata.py +++ b/CaSSAndRA/src/backend/data/mapdata.py @@ -33,6 +33,7 @@ class Perimeter: gotopoints: pd.DataFrame = field(default_factory=lambda: pd.DataFrame()) gotopoint: pd.DataFrame = field(default_factory=lambda: pd.DataFrame()) mowpath: pd.DataFrame = field(default_factory=lambda: pd.DataFrame()) + mowpathId: str = None preview: pd.DataFrame = field(default_factory=lambda: pd.DataFrame()) previewId: str = None obstacles: pd.DataFrame = field(default_factory=lambda: pd.DataFrame()) @@ -226,19 +227,26 @@ def create(self, name: str) -> None: self.preview = pd.DataFrame() self.mowpath = pd.DataFrame() self.obstacles = pd.DataFrame() - self.map_id = str(uuid.uuid4()) self.create_perimeter_polygon() self.create_perimeter_for_plot() self.create_points_from_polygon() self.create_go_to_points() self.create_networkx_graph() self.save_map_name() + self.map_id = str(uuid.uuid4()) + self.previewId = str(uuid.uuid4()) + self.mowpathId = str(uuid.uuid4()) def calc_route_preview(self, route: list) -> None: self.preview = pd.DataFrame(route) self.preview.columns = ['X', 'Y'] self.preview['type'] = 'preview route' self.previewId = str(uuid.uuid4()) + + def calc_route_mowpath(self) -> None: + self.mowpath = self.preview + self.mowpath['type'] = 'way' + self.mowpathId = str(uuid.uuid4()) def read_map_name(self) -> str: try: diff --git a/CaSSAndRA/src/backend/data/scheduledata.py b/CaSSAndRA/src/backend/data/scheduledata.py index eef7b93..68274fd 100644 --- a/CaSSAndRA/src/backend/data/scheduledata.py +++ b/CaSSAndRA/src/backend/data/scheduledata.py @@ -118,8 +118,7 @@ def create_start_cmd(self) -> None: current_map.calculating = True path.calc_task(tasks_order_table[self.dayweek].subtasks, tasks_order_table[self.dayweek].subtasks_parameters) current_map.calculating = False - current_map.mowpath = current_map.preview - current_map.mowpath['type'] = 'way' + current_map.calc_route_mowpath() cmdlist.cmd_mow = True self.job_started = True else: diff --git a/CaSSAndRA/src/components/state/buttongroupcontrol.py b/CaSSAndRA/src/components/state/buttongroupcontrol.py index fda28a3..8144725 100644 --- a/CaSSAndRA/src/components/state/buttongroupcontrol.py +++ b/CaSSAndRA/src/components/state/buttongroupcontrol.py @@ -109,8 +109,7 @@ def perfom_cmd(n_clicks_bgo: int, if active_bh: cmdlist.cmd_dock = True elif active_bma: - current_map.mowpath = current_map.preview - current_map.mowpath['type'] = 'way' + current_map.calc_route_mowpath() cmdlist.cmd_mow = True elif active_bss: current_map.task_progress = 0 @@ -119,8 +118,7 @@ def perfom_cmd(n_clicks_bgo: int, if len(current_task.subtasks['name'].unique()) == 1: saveddata.update_task_preview(tasks.saved, current_map.preview) current_map.calculating = False - current_map.mowpath = current_map.preview - current_map.mowpath['type'] = 'way' + current_map.calc_route_mowpath() cmdlist.cmd_mow = True elif active_bgt: cmdlist.cmd_goto = True diff --git a/CaSSAndRA/src/components/tasks/buttons.py b/CaSSAndRA/src/components/tasks/buttons.py index bb993ba..0bdb62c 100644 --- a/CaSSAndRA/src/components/tasks/buttons.py +++ b/CaSSAndRA/src/components/tasks/buttons.py @@ -43,8 +43,7 @@ def start_selected_tasks_order(bsst_nclicks: int) -> bool: if len(current_task.subtasks['name'].unique()) == 1: saveddata.update_task_preview(tasks.saved, current_map.preview) current_map.calculating = False - current_map.mowpath = current_map.preview - current_map.mowpath['type'] = 'way' + current_map.calc_route_mowpath() cmdlist.cmd_mow = True return False @@ -59,8 +58,7 @@ def load_selected_tasks_order(blsto_nclicks: int) -> bool: if len(current_task.subtasks['name'].unique()) == 1: saveddata.update_task_preview(tasks.saved, current_map.preview) current_map.calculating = False - current_map.mowpath = current_map.preview - current_map.mowpath['type'] = 'way' + current_map.calc_route_mowpath() cmdlist.cmd_take_map = True return False