From 83e897e2e501e7a463ee43956f32ddfa95ccdf28 Mon Sep 17 00:00:00 2001
From: Tommy Persson <tommy.persson@liu.se>
Date: Sat, 8 Mar 2025 15:11:42 +0100
Subject: [PATCH] Workaround for strange behaviour when on agent not seeing
 heartbet from another agent.

---
 lrs_json_api/bridge.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lrs_json_api/bridge.py b/lrs_json_api/bridge.py
index 27ba1e7..ff5d9fd 100644
--- a/lrs_json_api/bridge.py
+++ b/lrs_json_api/bridge.py
@@ -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))
-- 
GitLab