Fixed broker forwarder
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user