Forgot to set up notify event

This commit is contained in:
2026-01-03 16:17:06 +01:00
parent 3f2670866b
commit d56189ccee
2 changed files with 17 additions and 19 deletions

View File

@@ -6,22 +6,24 @@ from services.mqtt_service import MQTTService
class MQTTForwarder:
client_id : str
local_broker : MQTTService
central_broker : MQTTService
_client_id : str
_local_broker : MQTTService
_central_broker : MQTTService
_qos : int
def __init__(self, client_id : str, src_mqtt: MQTTService, dst_mqtt: MQTTService):
self.client_id = client_id
self.local_broker = src_mqtt
self.central_broker = dst_mqtt
def __init__(self, client_id : str, src_mqtt: MQTTService, dst_mqtt: MQTTService, qos : int):
self._client_id = client_id
self._local_broker = src_mqtt
self._central_broker = dst_mqtt
self._qos = qos
def start(self, src_topic: str, dst_topic: str):
try:
def forward_handler(topic: str, msg: str):
forwarded_msg = self.__wrap_data(msg)
self.central_broker.publish(dst_topic, forwarded_msg)
self._central_broker.publish(dst_topic, forwarded_msg, self._qos)
self.local_broker.subscribe(src_topic, forward_handler)
self._local_broker.subscribe(src_topic, forward_handler)
except Exception as e:
print(f"An error occurred while forwarding from {src_topic} to {dst_topic}: {e}")
@@ -30,7 +32,7 @@ class MQTTForwarder:
result = {}
data = json.loads(msg)
result["timestamp"] = int(time.time())
result["systemId"] = self.client_id
result["systemId"] = self._client_id
result["data"] = {}
for keys in data:
result["data"][keys] = data[keys]