Skip to content

Commit d9b0ccf

Browse files
committed
docs: 更新Mqtt直连接入、网关接入文档
1 parent a648716 commit d9b0ccf

2 files changed

Lines changed: 540 additions & 106 deletions

File tree

‎docs/device-connect/mqtt-device-rule.md‎

Lines changed: 94 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -95,39 +95,101 @@ sidebar_position: 11
9595

9696
**主题:** `devices/telemetry`
9797

98-
```json title="遥测数据格式示例"
98+
#### 实时上报模式
99+
100+
直接键值对格式,系统自动使用服务器接收时间作为时间戳。
101+
102+
```json title="实时遥测数据格式示例"
99103
{
100-
"temperature": 28.5,
104+
"temperature": 25.5,
105+
"humidity": 65.0,
101106
"switch": true
102107
}
103108
```
104109

110+
#### 历史上报模式
111+
112+
时间序列数组格式,每条记录包含时间戳和对应的数据值。
113+
114+
```json title="历史遥测数据格式示例"
115+
[
116+
{"ts": 1609459200, "values": {"temperature": 22.5, "humidity": 60.0}},
117+
{"ts": 1609462800, "values": {"temperature": 23.0, "humidity": 61.5}}
118+
]
119+
```
120+
121+
:::info 格式识别规则
122+
- **实时模式**:根级别为键值对对象
123+
- **历史模式**:根级别为数组,数组元素包含 `ts` 和 `values` 字段
124+
125+
**字段说明:**
126+
- `ts`:Unix时间戳(秒级),数据采集时间
127+
- `values`:该时间点的遥测数据键值对
128+
:::
129+
105130
### 📋 属性数据上报
106131

107132
**主题:** `devices/attributes/{message_id}`
108133

109134
```json title="属性数据格式示例"
110135
{
111-
"ip": "127.0.0.1",
112-
"mac": "xxxxxxxxxx",
113-
"port": 1883
136+
"ip": "192.168.1.100",
137+
"mac": "00:11:22:33:44:55",
138+
"version": "1.0.0"
114139
}
115140
```
116141

117142
### 🎯 事件数据上报
118143

119144
**主题:** `devices/event/{message_id}`
120145

121-
```json title="事件数据格式示例"
146+
#### 实时上报模式
147+
148+
```json title="实时事件数据格式示例"
122149
{
123-
"method": "FindAnimal",
150+
"method": "AlarmTriggered",
124151
"params": {
125-
"count": 2,
126-
"animalType": "cat"
152+
"level": "high",
153+
"sensor": "temperature"
127154
}
128155
}
129156
```
130157

158+
#### 历史上报模式
159+
160+
时间序列数组格式,每条记录包含时间戳和对应的事件信息。
161+
162+
```json title="历史事件数据格式示例"
163+
[
164+
{
165+
"ts": 1609459200000,
166+
"method": "AlarmTriggered",
167+
"params": {
168+
"level": "high",
169+
"sensor": "temperature"
170+
}
171+
},
172+
{
173+
"ts": 1609462800000,
174+
"method": "DeviceStarted",
175+
"params": {
176+
"version": "1.0.0",
177+
"mode": "normal"
178+
}
179+
}
180+
]
181+
```
182+
183+
:::info 格式识别规则
184+
- **实时模式**:根级别包含 `method` 字段且不包含 `ts` 字段
185+
- **历史模式**:根级别为数组,数组元素同时包含 `ts` 和 `method` 字段
186+
187+
**字段说明:**
188+
- `ts`:Unix时间戳(毫秒级),事件发生时间
189+
- `method`:事件方法名,必填字段
190+
- `params`:事件参数,可选字段
191+
:::
192+
131193
### 📦 OTA升级进度上报
132194

133195
**主题:** `ota/devices/progress`
@@ -145,7 +207,7 @@ sidebar_position: 11
145207
```json title="升级失败上报"
146208
{
147209
"step": "-1",
148-
"desc": "OTA升级失败,请求不到升级包信息。",
210+
"desc": "OTA升级失败,下载升级包失败",
149211
"module": "MCU"
150212
}
151213
```
@@ -166,8 +228,8 @@ sidebar_position: 11
166228

167229
```json title="控制指令格式示例"
168230
{
169-
"temperature": 28.5,
170-
"light": 2000,
231+
"temperature": 25.0,
232+
"brightness": 80,
171233
"switch": true
172234
}
173235
```
@@ -178,9 +240,9 @@ sidebar_position: 11
178240

179241
```json title="属性设置格式示例"
180242
{
181-
"ip": "127.0.0.1",
182-
"mac": "xxxxxxxxxx",
183-
"port": 1883
243+
"ip": "192.168.1.100",
244+
"heartbeat": 30,
245+
"report_interval": 60
184246
}
185247
```
186248

@@ -198,7 +260,7 @@ sidebar_position: 11
198260
**查询指定属性:**
199261
```json title="查询指定属性"
200262
{
201-
"keys": ["temp", "hum"]
263+
"keys": ["temperature", "humidity"]
202264
}
203265
```
204266

@@ -208,10 +270,10 @@ sidebar_position: 11
208270

209271
```json title="命令执行格式示例"
210272
{
211-
"method": "ReSet",
273+
"method": "Restart",
212274
"params": {
213-
"switch": 1,
214-
"light": "close"
275+
"delay": 5,
276+
"mode": "safe"
215277
}
216278
}
217279
```
@@ -236,18 +298,18 @@ sidebar_position: 11
236298

237299
```json title="OTA升级任务示例"
238300
{
239-
"id": "123",
301+
"id": "1001",
240302
"code": 200,
241303
"params": {
242-
"version": "1.1",
243-
"size": 432945,
244-
"url": "http://dev.thingspane.cn/files/ota/s121jg3245gg.zip",
245-
"signMethod": "Md5",
246-
"sign": "a243fgh4b9v",
304+
"version": "2.0.1",
305+
"size": 1024000,
306+
"url": "https://example.com/firmware/device_v2.0.1.bin",
307+
"signMethod": "MD5",
308+
"sign": "d41d8cd98f00b204e9800998ecf8427e",
247309
"module": "MCU",
248310
"extData": {
249-
"key1": "value1",
250-
"key2": "value2"
311+
"description": "Fix temperature sensor bug",
312+
"mandatory": true
251313
}
252314
}
253315
}
@@ -272,7 +334,7 @@ sidebar_position: 11
272334
{
273335
"result": 0,
274336
"message": "success",
275-
"ts": 1609143039
337+
"ts": 1609459200
276338
}
277339
```
278340

@@ -282,8 +344,8 @@ sidebar_position: 11
282344
"result": 1,
283345
"errcode": "INVALID_PARAM",
284346
"message": "Parameter validation failed",
285-
"ts": 1609143039,
286-
"method": "ReSet"
347+
"ts": 1609459200,
348+
"method": "Restart"
287349
}
288350
```
289351

@@ -292,8 +354,8 @@ sidebar_position: 11
292354
{
293355
"result": 0,
294356
"message": "Command executed successfully",
295-
"ts": 1609143039,
296-
"method": "ReSet"
357+
"ts": 1609459200,
358+
"method": "Restart"
297359
}
298360
```
299361

0 commit comments

Comments
 (0)