From 4110e6823b149fb81853e97ff5eb2736a73def30 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 29 Dec 2025 13:03:30 +0100 Subject: [PATCH] Fixed broker forwarder --- api-customer/app.py | 1 + api-customer/src/controllers/mqtt_forwarder.py | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/api-customer/app.py b/api-customer/app.py index 7cdebe77..ab2f8eea 100644 --- a/api-customer/app.py +++ b/api-customer/app.py @@ -21,5 +21,6 @@ if __name__ == '__main__': api_broker = MQTTService("192.168.15.120", 8883) forwarder = MQTTForwarder(client_id, local_broker, api_broker) + forwarder.start(f"/customer/${client_id}/#", f"/board-mate/${client_id}/telemetry") app.run(host="0.0.0.0", port=5000, debug=False) diff --git a/api-customer/src/controllers/mqtt_forwarder.py b/api-customer/src/controllers/mqtt_forwarder.py index 1725cad3..1ea04742 100644 --- a/api-customer/src/controllers/mqtt_forwarder.py +++ b/api-customer/src/controllers/mqtt_forwarder.py @@ -15,11 +15,14 @@ class MQTTForwarder: self.local_broker = local_mqtt self.central_broker = central_mqtt - def start(self): - self.local_broker.subscribe("board-mate/", self.__forward) + def start(self, src_topic : str, dst_topic : str) -> None: + def handler(msg:str): + self.__forward(msg, dst_topic) - def __forward(self, msg: str): - self.central_broker.publish(self.client_id, f"/board-mate/${self.client_id}/telemetry", msg) + self.local_broker.subscribe(src_topic, handler) + + def __forward(self, msg: str, dst_topic) -> None: + self.central_broker.publish(self.client_id, dst_topic, msg) """def start(self): self.local.subscribe("board-mate/+/telemetry", self.handle_message)