refactor: MQTT 主题方向 down→srv, up→dev

- dld960/{sn}/down → dld960/{sn}/srv
- dld960/{sn}/up → dld960/{sn}/dev
- 通配符 dld960/+/up → dld960/+/dev
This commit is contained in:
wangfq
2026-07-07 09:42:35 +08:00
parent 213716033c
commit 770d67346f
2 changed files with 28 additions and 28 deletions
+4 -4
View File
@@ -2,7 +2,7 @@
DLD960 IoT MQTT 协议定义 DLD960 IoT MQTT 协议定义
基于《DLD960_IoT_MQTT协议.md》V1.01 基于《DLD960_IoT_MQTT协议.md》V1.01
双主题结构:{sn}/down(服务器下发)、{sn}/up(设备上报) 双主题结构:{sn}/srv(服务器下发)、{sn}/dev(设备上报)
消息类型由 JSON `cmd` 字段区分。 消息类型由 JSON `cmd` 字段区分。
""" """
@@ -18,12 +18,12 @@ from dataclasses import dataclass, field, asdict
def topic_down(dev_serial: str) -> str: def topic_down(dev_serial: str) -> str:
"""服务器下发 — 设备订阅此主题接收所有命令""" """服务器下发 — 设备订阅此主题接收所有命令"""
return f"dld960/{dev_serial}/down" return f"dld960/{dev_serial}/srv"
def topic_up(dev_serial: str) -> str: def topic_up(dev_serial: str) -> str:
"""设备上报 — 设备发布到此主题(数据、事件、心跳、响应)""" """设备上报 — 设备发布到此主题(数据、事件、心跳、响应)"""
return f"dld960/{dev_serial}/up" return f"dld960/{dev_serial}/dev"
# 保持向后兼容的别名(4.7 iot_topic_set 仍使用 topic_pub / topic_sub # 保持向后兼容的别名(4.7 iot_topic_set 仍使用 topic_pub / topic_sub
@@ -38,7 +38,7 @@ def topic_dev_sub(dev_serial: str) -> str:
# 服务器端通配符订阅(监听所有设备) # 服务器端通配符订阅(监听所有设备)
TOPIC_ALL_DEVICE_UP = "dld960/+/up" TOPIC_ALL_DEVICE_UP = "dld960/+/dev"
# ============================================================ # ============================================================
+24 -24
View File
@@ -28,21 +28,21 @@ dld960/{dev_serial}/{direction}
| 字段 | 说明 | | 字段 | 说明 |
|------|------| |------|------|
| `dev_serial` | 设备序列码(6字节十六进制字符串,如 `A1B2C3D4E5F6` | | `dev_serial` | 设备序列码(6字节十六进制字符串,如 `A1B2C3D4E5F6` |
| `direction` | `down` = 服务器下发(设备订阅),`up` = 设备上报(服务器订阅) | | `direction` | `srv` = 服务器下发(设备订阅),`dev` = 设备上报(服务器订阅) |
### 1.2.1 服务器下发 Topic — `dld960/{sn}/down` ### 1.2.1 服务器下发 Topic — `dld960/{sn}/srv`
设备订阅此主题,接收服务器下发的所有命令(配置设置、查询、控制等)。 设备订阅此主题,接收服务器下发的所有命令(配置设置、查询、控制等)。
服务器发布到此主题。 服务器发布到此主题。
对应串口 CMD0x09 ~ 0x1F, 0x63, 0x64, 0xC5 等。 对应串口 CMD0x09 ~ 0x1F, 0x63, 0x64, 0xC5 等。
### 1.2.2 设备上报 Topic — `dld960/{sn}/up` ### 1.2.2 设备上报 Topic — `dld960/{sn}/dev`
设备发布到此主题,上报线圈数据、事件、心跳及命令响应。 设备发布到此主题,上报线圈数据、事件、心跳及命令响应。
服务器订阅此主题接收所有设备上行消息。 服务器订阅此主题接收所有设备上行消息。
服务器端可订阅通配符 `dld960/+/up` 监听所有设备。 服务器端可订阅通配符 `dld960/+/dev` 监听所有设备。
--- ---
@@ -127,7 +127,7 @@ dld960/{dev_serial}/{direction}
## 4.1 更改设备序列码 `dev_serial_set` ## 4.1 更改设备序列码 `dev_serial_set`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -142,7 +142,7 @@ dld960/{dev_serial}/{direction}
} }
``` ```
**响应:** Topic: `dld960/{sn}/up` **响应:** Topic: `dld960/{sn}/dev`
```json ```json
{ {
@@ -156,7 +156,7 @@ dld960/{dev_serial}/{direction}
## 4.2 查询设备信息 `dev_info_query` ## 4.2 查询设备信息 `dev_info_query`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -210,7 +210,7 @@ dld960/{dev_serial}/{direction}
## 4.3 设置 SSC 网络配置 `ssc_net_set` ## 4.3 设置 SSC 网络配置 `ssc_net_set`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -253,7 +253,7 @@ dld960/{dev_serial}/{direction}
## 4.4 查询 SSC 网络配置 `ssc_net_query` ## 4.4 查询 SSC 网络配置 `ssc_net_query`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -269,7 +269,7 @@ dld960/{dev_serial}/{direction}
## 4.5 设置 IoT 网络配置 `iot_net_set` ## 4.5 设置 IoT 网络配置 `iot_net_set`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -300,7 +300,7 @@ dld960/{dev_serial}/{direction}
## 4.6 查询 IoT 网络配置 `iot_net_query` ## 4.6 查询 IoT 网络配置 `iot_net_query`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -316,7 +316,7 @@ dld960/{dev_serial}/{direction}
## 4.7 设置设备 Topic `iot_topic_set` ## 4.7 设置设备 Topic `iot_topic_set`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -337,7 +337,7 @@ dld960/{dev_serial}/{direction}
## 4.8 查询设备 Topic `iot_topic_query` ## 4.8 查询设备 Topic `iot_topic_query`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -353,7 +353,7 @@ dld960/{dev_serial}/{direction}
## 4.9 验证设备密码 `pwd_verify` ## 4.9 验证设备密码 `pwd_verify`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -386,7 +386,7 @@ dld960/{dev_serial}/{direction}
## 4.10 设置设备密码 `pwd_set` ## 4.10 设置设备密码 `pwd_set`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -406,7 +406,7 @@ dld960/{dev_serial}/{direction}
## 4.11 设备出厂初始化 `factory_reset` ## 4.11 设备出厂初始化 `factory_reset`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -432,7 +432,7 @@ dld960/{dev_serial}/{direction}
## 4.12 设备复位 `device_reset` ## 4.12 设备复位 `device_reset`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -448,7 +448,7 @@ dld960/{dev_serial}/{direction}
## 4.13 设置车检器多路参数 `loop_param_set` ## 4.13 设置车检器多路参数 `loop_param_set`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -537,7 +537,7 @@ dld960/{dev_serial}/{direction}
## 4.14 读取车检器多路参数 `loop_param_query` ## 4.14 读取车检器多路参数 `loop_param_query`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -588,7 +588,7 @@ dld960/{dev_serial}/{direction}
## 4.15 设置主动上报 `report_config` ## 4.15 设置主动上报 `report_config`
> Topic: `dld960/{sn}/down` > Topic: `dld960/{sn}/srv`
**请求:** **请求:**
@@ -627,7 +627,7 @@ dld960/{dev_serial}/{direction}
## 5.1 线圈传感数据 `loop_data` ## 5.1 线圈传感数据 `loop_data`
> Topic: `dld960/{sn}/up` > Topic: `dld960/{sn}/dev`
> QoS: 0/1 > QoS: 0/1
```json ```json
@@ -713,7 +713,7 @@ dld960/{dev_serial}/{direction}
## 5.2 事件上报 `event_report` ## 5.2 事件上报 `event_report`
> Topic: `dld960/{sn}/up` > Topic: `dld960/{sn}/dev`
设备检测到事件时主动上报,非周期性。 设备检测到事件时主动上报,非周期性。
@@ -753,7 +753,7 @@ dld960/{dev_serial}/{direction}
## 5.3 设备心跳 `heartbeat` ## 5.3 设备心跳 `heartbeat`
> Topic: `dld960/{sn}/up` > Topic: `dld960/{sn}/dev`
> 周期:默认 60 秒 > 周期:默认 60 秒
```json ```json
@@ -784,4 +784,4 @@ dld960/{dev_serial}/{direction}
| 版本 | 修订时间 | 修订说明 | 修订人 | | 版本 | 修订时间 | 修订说明 | 修订人 |
|------|----------|----------|--------| |------|----------|----------|--------|
| V1.00 | 2026-06-22 | 初始版本,基于串口协议 V1.01 | wangfq | | V1.00 | 2026-06-22 | 初始版本,基于串口协议 V1.01 | wangfq |
| V1.01 | 2026-07-07 | Topic 压缩为双主题(`{sn}/up` + `{sn}/down`),消息类型由 `cmd` 字段区分 | wangfq | | V1.01 | 2026-07-07 | Topic 压缩为双主题(`{sn}/srv` + `{sn}/dev`),消息类型由 `cmd` 字段区分 | wangfq |