From 1b11a5a8dde96fdec069aafa8ee9cf2774c0fab5 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 5 Nov 2025 22:25:17 +0100 Subject: [PATCH] Fix BirdNET-Pi MQTT callback for paho 2.x --- birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py b/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py index af215a6b9..47a5e8283 100644 --- a/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py +++ b/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py @@ -113,7 +113,14 @@ def automatic_mqtt_publish(file, detection, path): log.info("Posted to MQTT: ok") -mqttc = mqtt.Client("birdnet_mqtt", callback_api_version=4) +# Create MQTT client using legacy callback API when available for +# compatibility with paho-mqtt >= 2.0 +callback_api = getattr(mqtt, "CallbackAPIVersion", None) + +if callback_api is not None: + mqttc = mqtt.Client("birdnet_mqtt", callback_api_version=callback_api.VERSION1) +else: + mqttc = mqtt.Client("birdnet_mqtt") mqttc.username_pw_set(mqtt_user, mqtt_pass) mqttc.on_connect = on_connect