Skip to content

Commit

Permalink
Fixed last will message for API
Browse files Browse the repository at this point in the history
Some preparations for new feautures
  • Loading branch information
EinEinfach committed Jun 25, 2024
1 parent 9901d13 commit 6fbc80f
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CaSSAndRA/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions CaSSAndRA/src/backend/backendserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,19 @@ 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:
time.sleep(0.1)
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
Expand Down
12 changes: 4 additions & 8 deletions CaSSAndRA/src/backend/comm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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:
Expand All @@ -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')
Expand Down
4 changes: 3 additions & 1 deletion CaSSAndRA/src/backend/comm/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion CaSSAndRA/src/backend/data/appdata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging
logger = logging.getLogger(__name__)

version = '0.118.0'
version = '0.119.0'
10 changes: 9 additions & 1 deletion CaSSAndRA/src/backend/data/mapdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions CaSSAndRA/src/backend/data/scheduledata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions CaSSAndRA/src/components/state/buttongroupcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions CaSSAndRA/src/components/tasks/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand Down

0 comments on commit 6fbc80f

Please sign in to comment.