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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user