Fix MQTT client configuration and callback to resolve breaking issues
- Reverted MQTT client to MQTTv311 to avoid compatibility issues. - Updated on_connect method to match expected arguments for MQTTv5. - Fixed deprecation and runtime errors for proper operation.
This commit is contained in:
@@ -28,7 +28,7 @@ UPPER_COLOR = np.array([35, 255, 255])
|
|||||||
# Track if the initial snapshot has been processed
|
# Track if the initial snapshot has been processed
|
||||||
initial_snapshot_processed = False
|
initial_snapshot_processed = False
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, reasonCode, properties=None):
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
print("Connected successfully to MQTT broker")
|
print("Connected successfully to MQTT broker")
|
||||||
client.subscribe(MQTT_SNAPSHOT_TOPIC, qos=1)
|
client.subscribe(MQTT_SNAPSHOT_TOPIC, qos=1)
|
||||||
@@ -131,7 +131,7 @@ if len(sys.argv) > 1:
|
|||||||
print(f"File not found: {image_file}")
|
print(f"File not found: {image_file}")
|
||||||
|
|
||||||
# Set up MQTT client for normal operation
|
# Set up MQTT client for normal operation
|
||||||
client = mqtt.Client(protocol=mqtt.MQTTv5)
|
client = mqtt.Client(protocol=mqtt.MQTTv311)
|
||||||
client.username_pw_set(MQTT_USERNAME, MQTT_PASSWORD)
|
client.username_pw_set(MQTT_USERNAME, MQTT_PASSWORD)
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
|
|||||||
Reference in New Issue
Block a user