实现在心跳中采集各设备信息
This commit is contained in:
71
RELAY_API.md
71
RELAY_API.md
@@ -103,6 +103,29 @@ ws://[server_address]:[port]/ws/device?device_id=[device_id]
|
||||
- `command`: 指令名称,固定为"query_all_device_status"
|
||||
- `timestamp`: 指令发送时间
|
||||
|
||||
### 3.4 心跳包指令
|
||||
|
||||
平台向中继设备发送心跳包指令,用于检测设备连接状态并获取下级设备状态信息。
|
||||
|
||||
**请求格式**
|
||||
```json
|
||||
{
|
||||
"type": "command",
|
||||
"command": "heartbeat",
|
||||
"data": {
|
||||
"timestamp": 1672545600
|
||||
},
|
||||
"timestamp": "2023-01-01T12:00:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
**参数说明**
|
||||
- `type`: 消息类型,固定为"command"
|
||||
- `command`: 指令名称,固定为"heartbeat"
|
||||
- `data`: 指令数据
|
||||
- `timestamp`: 时间戳(Unix时间戳格式)
|
||||
- `timestamp`: 指令发送时间
|
||||
|
||||
## 4. 响应接口
|
||||
|
||||
### 4.1 设备控制响应
|
||||
@@ -167,6 +190,48 @@ ws://[server_address]:[port]/ws/device?device_id=[device_id]
|
||||
}
|
||||
```
|
||||
|
||||
### 4.4 心跳包响应
|
||||
|
||||
中继设备响应心跳包指令,返回自身及下级设备的状态信息。
|
||||
|
||||
**响应格式**
|
||||
```json
|
||||
{
|
||||
"type": "response",
|
||||
"command": "heartbeat",
|
||||
"data": {
|
||||
"devices": [
|
||||
{
|
||||
"device_id": "relay-001",
|
||||
"device_type": "relay",
|
||||
"status": "running"
|
||||
},
|
||||
{
|
||||
"device_id": "fan-001",
|
||||
"device_type": "fan",
|
||||
"status": "running"
|
||||
},
|
||||
{
|
||||
"device_id": "curtain-001",
|
||||
"device_type": "water_curtain",
|
||||
"status": "stopped"
|
||||
}
|
||||
]
|
||||
},
|
||||
"timestamp": "2023-01-01T12:00:05Z"
|
||||
}
|
||||
```
|
||||
|
||||
**参数说明**
|
||||
- `type`: 消息类型,固定为"response"
|
||||
- `command`: 指令名称,固定为"heartbeat"
|
||||
- `data`: 响应数据
|
||||
- `devices`: 设备列表
|
||||
- `device_id`: 设备唯一标识符
|
||||
- `device_type`: 设备类型
|
||||
- `status`: 设备状态(如: running, stopped, online, offline等)
|
||||
- `timestamp`: 平台发送的时间戳, 需要原封不动的返回
|
||||
|
||||
## 5. 请求-响应机制
|
||||
|
||||
平台在发送指令后会等待中继设备的响应,超时时间由配置文件决定,默认为5秒。
|
||||
@@ -277,6 +342,7 @@ if err := response.ParseData(&status); err != nil {
|
||||
|------|------|
|
||||
| fan | 风机设备 |
|
||||
| water_curtain | 水帘设备 |
|
||||
| relay | 中继设备 |
|
||||
|
||||
## 10. 动作说明
|
||||
|
||||
@@ -292,4 +358,7 @@ if err := response.ParseData(&status); err != nil {
|
||||
| success | 操作成功 |
|
||||
| failed | 操作失败 |
|
||||
| running | 设备运行中 |
|
||||
| stopped | 设备已停止 |
|
||||
| stopped | 设备已停止 |
|
||||
| online | 设备在线 |
|
||||
| offline | 设备离线 |
|
||||
| active | 设备激活 |
|
||||
Reference in New Issue
Block a user