Oopsie
This commit is contained in:
@@ -18,14 +18,14 @@ class MQTTForwarder:
|
|||||||
def start(self, src_topic: str, dst_topic: str):
|
def start(self, src_topic: str, dst_topic: str):
|
||||||
try:
|
try:
|
||||||
def forward_handler(topic: str, msg: str):
|
def forward_handler(topic: str, msg: str):
|
||||||
forwarded_msg = self.__wrapData(msg)
|
forwarded_msg = self.__wrap_data(msg)
|
||||||
self.central_broker.publish(dst_topic, forwarded_msg)
|
self.central_broker.publish(dst_topic, forwarded_msg)
|
||||||
|
|
||||||
self.local_broker.subscribe(src_topic, forward_handler)
|
self.local_broker.subscribe(src_topic, forward_handler)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"An error occurred while forwarding from {src_topic} to {dst_topic}: {e}")
|
print(f"An error occurred while forwarding from {src_topic} to {dst_topic}: {e}")
|
||||||
|
|
||||||
def __wrapData(self, msg : str):
|
def __wrap_data(self, msg : str):
|
||||||
result = {}
|
result = {}
|
||||||
data = json.loads(msg)
|
data = json.loads(msg)
|
||||||
result["timestamp"] = int(time.time())
|
result["timestamp"] = int(time.time())
|
||||||
@@ -33,4 +33,4 @@ class MQTTForwarder:
|
|||||||
result["data"] = {}
|
result["data"] = {}
|
||||||
for keys in data:
|
for keys in data:
|
||||||
result["data"][keys] = data[keys]
|
result["data"][keys] = data[keys]
|
||||||
|
return result
|
||||||
Reference in New Issue
Block a user