feat: MQTT 协议 V1.01 — Topic 压缩为双主题 (up/down)

- 7个主题压缩为2个: dld960/{sn}/down + dld960/{sn}/up
- 消息类型由 JSON cmd 字段区分,不再依赖 topic 路径
- protocol.py: topic_up()/topic_down() 替代旧7个函数
- mqtt_client.py: 4个通配符订阅→1个 dld960/+/up
- main.py: 消息路由改为 cmd 匹配,协议Topic树简化
- 文档更新 V1.01
This commit is contained in:
wangfq
2026-07-07 09:18:29 +08:00
parent d29e16acc8
commit 213716033c
4 changed files with 86 additions and 125 deletions
+2 -8
View File
@@ -68,14 +68,8 @@ class MqttClient:
self._connected = True
self._notify_status(True, "已连接到 Broker")
from .protocol import (
TOPIC_ALL_CONFIG_RESP, TOPIC_ALL_DATA_LOOP,
TOPIC_ALL_DATA_EVENT, TOPIC_ALL_STATUS
)
client.subscribe(TOPIC_ALL_CONFIG_RESP, qos=1)
client.subscribe(TOPIC_ALL_DATA_LOOP, qos=1)
client.subscribe(TOPIC_ALL_DATA_EVENT, qos=1)
client.subscribe(TOPIC_ALL_STATUS, qos=0)
from .protocol import TOPIC_ALL_DEVICE_UP
client.subscribe(TOPIC_ALL_DEVICE_UP, qos=1)
else:
self._connected = False
self._notify_status(False, f"连接失败 (rc={rc})")