From 213c0ddc2d52f644c0cb302b3581d3f7ef302c46 Mon Sep 17 00:00:00 2001 From: wangfq Date: Mon, 6 Jul 2026 21:32:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(DBNMQTTool):=20paho-mqtt=20disconnect=20?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E7=AD=BE=E5=90=8D=E5=85=BC=E5=AE=B9=20v1/v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _on_disconnect: 用 *args 兼容 v1(3参数) 和 v2(5参数) - Client 构造加 callback_api_version=VERSION2 - _on_connect 签名保持不变 (v2) --- DBNMQTTool/.requirements.txt.swp | Bin 0 -> 1024 bytes DBNMQTTool/dbn_mqtt_tool/mqtt_client.py | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 DBNMQTTool/.requirements.txt.swp diff --git a/DBNMQTTool/.requirements.txt.swp b/DBNMQTTool/.requirements.txt.swp new file mode 100644 index 0000000000000000000000000000000000000000..6616edadab2ad00e8bfe5efb4b0a742e0d6b0271 GIT binary patch literal 1024 zcmYc?$V<%2S1{KzVn6|5J0uv2^7Bhj1aWZ6(+YJ%Oe_o>amd4ji&6_qGmBDlQ}arS W^-3y;G8?9MlpYO%(GZ}12mk=v+Ydef literal 0 HcmV?d00001 diff --git a/DBNMQTTool/dbn_mqtt_tool/mqtt_client.py b/DBNMQTTool/dbn_mqtt_tool/mqtt_client.py index af9a844..72ff6ca 100644 --- a/DBNMQTTool/dbn_mqtt_tool/mqtt_client.py +++ b/DBNMQTTool/dbn_mqtt_tool/mqtt_client.py @@ -68,7 +68,6 @@ class MqttClient: self._connected = True self._notify_status(True, "已连接到 Broker") - # 订阅所有设备的上报 topic from .protocol import ( TOPIC_ALL_CONFIG_RESP, TOPIC_ALL_DATA_LOOP, TOPIC_ALL_DATA_EVENT, TOPIC_ALL_STATUS @@ -81,7 +80,7 @@ class MqttClient: self._connected = False self._notify_status(False, f"连接失败 (rc={rc})") - def _on_disconnect(self, client, userdata, flags, reason_code, properties=None): + def _on_disconnect(self, client, userdata, *args): self._connected = False self._notify_status(False, "已断开连接") @@ -107,6 +106,7 @@ class MqttClient: self._client = mqtt.Client( client_id=client_id, protocol=mqtt.MQTTv311, + callback_api_version=mqtt.CallbackAPIVersion.VERSION2, ) if self._config.username: self._client.username_pw_set(self._config.username, self._config.password)