fix: MQTT连接兼容paho-mqtt 1.x和2.x版本

- 添加paho-mqtt版本检测,兼容CallbackAPIVersion
- 修复回调函数签名,支持1.x的整数返回码和2.x的对象返回码
- 增强错误处理和日志输出
- 确保ResultReporter.initialize()被正确调用

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 16:02:32 +08:00
parent 6c6c9b4c03
commit cea4cb877b
2 changed files with 45 additions and 23 deletions

12
main.py
View File

@@ -122,9 +122,15 @@ class EdgeInferenceService:
def _init_reporter(self):
"""初始化结果上报器"""
self._reporter = ResultReporter()
self._reporter.initialize() # 初始化存储和MQTT连接
self._logger.info("结果上报器初始化成功")
try:
self._reporter = ResultReporter()
self._logger.info("ResultReporter 对象已创建,准备初始化...")
self._reporter.initialize() # 初始化存储和MQTT连接
self._logger.info("结果上报器初始化成功")
except Exception as e:
self._logger.error(f"结果上报器初始化失败: {e}")
import traceback
self._logger.error(traceback.format_exc())
def _init_algorithm_manager(self):
"""初始化算法管理器"""