From cbec68ccd882e9636e245d990ad79783bb6c4c08 Mon Sep 17 00:00:00 2001 From: Marcus Brown Date: Sun, 20 Oct 2024 18:17:46 +1100 Subject: [PATCH] Update MQTT client to use MQTTv5 and fix callback arguments - Updated MQTT client to use MQTTv5 to eliminate deprecated usage. - Corrected on_connect function signature and replaced deprecated `rc` with `reasonCode` for compatibility. --- dayglo_detector/dayglo_detector.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dayglo_detector/dayglo_detector.py b/dayglo_detector/dayglo_detector.py index f6727a6..0be633d 100644 --- a/dayglo_detector/dayglo_detector.py +++ b/dayglo_detector/dayglo_detector.py @@ -29,7 +29,7 @@ UPPER_COLOR = np.array([35, 255, 255]) initial_snapshot_processed = False def on_connect(client, userdata, flags, reasonCode, properties=None): - if rc == 0: + if reasonCode == 0: print("Connected successfully to MQTT broker") client.subscribe(MQTT_SNAPSHOT_TOPIC, qos=1) print(f"Subscribed to topic: {MQTT_SNAPSHOT_TOPIC}") @@ -37,7 +37,7 @@ def on_connect(client, userdata, flags, reasonCode, properties=None): # Publish initial rating of 0 publish_rating(0) else: - print(f"Failed to connect, return code {rc}") + print(f"Failed to connect, return code {reasonCode}") def publish_discovery_configurations(): rating_config = { @@ -131,7 +131,7 @@ if len(sys.argv) > 1: print(f"File not found: {image_file}") # Set up MQTT client for normal operation -client = mqtt.Client(protocol=mqtt.MQTTv311) +client = mqtt.Client(protocol=mqtt.MQTTv5) client.username_pw_set(MQTT_USERNAME, MQTT_PASSWORD) client.on_connect = on_connect client.on_message = on_message