Skip to content
Snippets Groups Projects
Commit 83e897e2 authored by Tommy Persson's avatar Tommy Persson
Browse files

Workaround for strange behaviour when on agent not seeing heartbet from another agent.

parent 6ecb936f
No related branches found
No related tags found
No related merge requests found
......@@ -326,11 +326,15 @@ class Bridge(Mqtt):
self.connect_publish("connected")
def get_topic_from_unit(self, unit, subtopic):
print("GET_TOPIC_FROM_UNIT unit:", unit)
print("GET_TOPIC_FROM_UNIT subtopic:", subtopic)
topic = ""
unit = unit.lstrip("/")
print("GET_TOPIC_FROM_UNIT unit:", unit, self.unit_to_prefix_map)
if unit in self.unit_to_prefix_map:
print("UNIT IN DICT unit:", unit)
topic = f'{self.unit_to_prefix_map[unit]}/{unit}/{subtopic}'
# self.get_logger().info(f'get_topic_from_unit: {unit} - {topic}')
self.get_logger().info(f'get_topic_from_unit: {unit} - {topic}')
return topic
......@@ -623,7 +627,7 @@ class Bridge(Mqtt):
topic = "/".join(topic_elements[5:])
#print("SELECTTOPIC:", topic)
#if agent == "spot0":
#if agent == "op2":
# print("TOPIC:", topic)
#if topic == "heartbeat":
......@@ -641,6 +645,7 @@ class Bridge(Mqtt):
if topic == "heartbeat":
print("HEARTBEAT:", agent, "/".join(topic_elements[:4]))
self.unit_to_prefix_map[agent] = "/".join(topic_elements[:4])
return
......@@ -1134,6 +1139,7 @@ class Bridge(Mqtt):
self.client.publish(topic, payload=request.msg)
response.success = True
else:
self.get_logger().error(f'BRIDGE: Could not find topic for unit: {unit}')
response.success = False
except Exception as exc:
print("EXCEPTION on_message", type(exc))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment