mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2025-02-22 09:19:51 +01:00
Cleanup
This commit is contained in:
parent
e743493ffd
commit
329bf6f3e6
@ -22,8 +22,6 @@ class MQTT():
|
|||||||
self.queue_lock = threading.Lock()
|
self.queue_lock = threading.Lock()
|
||||||
self.waiting_msgs = deque(maxlen=MQTT.QUEUE_MAXLEN)
|
self.waiting_msgs = deque(maxlen=MQTT.QUEUE_MAXLEN)
|
||||||
self.waiting_telemetry = set()
|
self.waiting_telemetry = set()
|
||||||
self.unacked_msgs = set()
|
|
||||||
self.client.user_data_set(self.unacked_msgs)
|
|
||||||
self.client.on_connect_fail = self.connect_failed
|
self.client.on_connect_fail = self.connect_failed
|
||||||
self.client.on_disconnect = self.disconnected
|
self.client.on_disconnect = self.disconnected
|
||||||
self.start()
|
self.start()
|
||||||
@ -86,7 +84,6 @@ class MQTT():
|
|||||||
|
|
||||||
def post_message(self, topic, data):
|
def post_message(self, topic, data):
|
||||||
mqtt_msg = self.client.publish(topic, data, qos=1)
|
mqtt_msg = self.client.publish(topic, data, qos=1)
|
||||||
self.unacked_msgs.add(mqtt_msg.mid)
|
|
||||||
self.waiting_telemetry.add(mqtt_msg)
|
self.waiting_telemetry.add(mqtt_msg)
|
||||||
|
|
||||||
def process_queue(self):
|
def process_queue(self):
|
||||||
@ -108,6 +105,8 @@ class MQTT():
|
|||||||
try:
|
try:
|
||||||
for msg in self.waiting_telemetry:
|
for msg in self.waiting_telemetry:
|
||||||
msg.wait_for_publish()
|
msg.wait_for_publish()
|
||||||
|
self.waiting_telemetry.clear()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log(f"An error occurred while publishing MQTT messages: {e}", RNS.LOG_ERROR)
|
RNS.log(f"An error occurred while publishing MQTT messages: {e}", RNS.LOG_ERROR)
|
||||||
RNS.trace_exception(e)
|
RNS.trace_exception(e)
|
||||||
@ -127,5 +126,4 @@ class MQTT():
|
|||||||
for topic in topics:
|
for topic in topics:
|
||||||
topic_path = f"{root_path}/{topic}"
|
topic_path = f"{root_path}/{topic}"
|
||||||
data = topics[topic]
|
data = topics[topic]
|
||||||
self.waiting_msgs.append((topic_path, data))
|
self.waiting_msgs.append((topic_path, data))
|
||||||
# RNS.log(f"{topic_path}: {data}") # TODO: Remove debug
|
|
Loading…
x
Reference in New Issue
Block a user