Skip to content

Commit 9eaefa8

Browse files
committed
feat: Conditional video deletion and improved MQTT logging
1 parent 92328e1 commit 9eaefa8

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

mqtt_publisher.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ def __init__(self):
1616
self.client = mqtt.Client()
1717
if self.username and self.password:
1818
self.client.username_pw_set(self.username, self.password)
19+
20+
self.client.on_connect = self.on_connect
1921

2022
try:
23+
logging.info(f"Attempting to connect to MQTT Broker: {self.broker}:{self.port}...")
2124
self.client.connect(self.broker, self.port, 60)
2225
self.client.loop_start()
23-
logging.info(f"Connected to MQTT Broker: {self.broker}:{self.port}")
2426
except Exception as e:
25-
logging.error(f"Failed to connect to MQTT Broker: {e}")
27+
logging.error(f"Failed to initiate MQTT connection: {e}")
28+
29+
def on_connect(self, client, userdata, flags, rc):
30+
if rc == 0:
31+
logging.info("Successfully connected to MQTT Broker!")
32+
else:
33+
logging.error(f"Failed to connect to MQTT Broker with return code {rc}")
2634

2735
def publish_user_data(self, user_id: str, balance: float, last_daily_date: str, last_daily_usage: float, yearly_charge: float, yearly_usage: float, month_charge: float, month_usage: float):
2836
if balance is not None:

0 commit comments

Comments
 (0)