|
|
@@ -178,6 +178,110 @@ DELETE /api/mqtt/:id
|
|
|
}
|
|
|
```
|
|
|
|
|
|
+### 7. 获取所有 BLE 配置
|
|
|
+
|
|
|
+```
|
|
|
+GET /api/ble
|
|
|
+```
|
|
|
+
|
|
|
+**响应示例:**
|
|
|
+```json
|
|
|
+{
|
|
|
+ "code": 0,
|
|
|
+ "message": "ok",
|
|
|
+ "data": [
|
|
|
+ {
|
|
|
+ "id": 1,
|
|
|
+ "device_name": "AI-Light",
|
|
|
+ "service_uuid": "b8b7e001-7a6b-4f4f-9a8b-11c0ffee0001",
|
|
|
+ "char_uuid": "b8b7e002-7a6b-4f4f-9a8b-11c0ffee0001",
|
|
|
+ "enabled": true
|
|
|
+ }
|
|
|
+ ]
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+### 8. 创建 BLE 配置
|
|
|
+
|
|
|
+```
|
|
|
+POST /api/ble
|
|
|
+```
|
|
|
+
|
|
|
+**请求体:**
|
|
|
+```json
|
|
|
+{
|
|
|
+ "device_name": "AI-Light",
|
|
|
+ "service_uuid": "b8b7e001-7a6b-4f4f-9a8b-11c0ffee0001",
|
|
|
+ "char_uuid": "b8b7e002-7a6b-4f4f-9a8b-11c0ffee0001",
|
|
|
+ "enabled": true
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+| 字段 | 类型 | 必填 | 默认值 | 说明 |
|
|
|
+|------|------|------|--------|------|
|
|
|
+| device_name | string | 否 | AI-Light | BLE 设备名称 |
|
|
|
+| service_uuid | string | 否 | b8b7e001-... | BLE 服务 UUID |
|
|
|
+| char_uuid | string | 否 | b8b7e002-... | BLE 特征 UUID |
|
|
|
+| enabled | boolean | 否 | true | 是否启用 |
|
|
|
+
|
|
|
+**响应示例:**
|
|
|
+```json
|
|
|
+{
|
|
|
+ "code": 0,
|
|
|
+ "message": "创建成功",
|
|
|
+ "data": {
|
|
|
+ "id": 1,
|
|
|
+ "device_name": "AI-Light",
|
|
|
+ "service_uuid": "b8b7e001-7a6b-4f4f-9a8b-11c0ffee0001",
|
|
|
+ "char_uuid": "b8b7e002-7a6b-4f4f-9a8b-11c0ffee0001",
|
|
|
+ "enabled": true
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+### 9. 获取单个 BLE 配置
|
|
|
+
|
|
|
+```
|
|
|
+GET /api/ble/:id
|
|
|
+```
|
|
|
+
|
|
|
+**路径参数:**
|
|
|
+| 参数 | 类型 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| id | integer | 配置 ID |
|
|
|
+
|
|
|
+### 10. 更新 BLE 配置
|
|
|
+
|
|
|
+```
|
|
|
+PUT /api/ble/:id
|
|
|
+```
|
|
|
+
|
|
|
+**路径参数:**
|
|
|
+| 参数 | 类型 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| id | integer | 配置 ID |
|
|
|
+
|
|
|
+**请求体:**
|
|
|
+```json
|
|
|
+{
|
|
|
+ "device_name": "MyLight",
|
|
|
+ "service_uuid": "xxx",
|
|
|
+ "char_uuid": "yyy",
|
|
|
+ "enabled": false
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+### 11. 删除 BLE 配置
|
|
|
+
|
|
|
+```
|
|
|
+DELETE /api/ble/:id
|
|
|
+```
|
|
|
+
|
|
|
+**路径参数:**
|
|
|
+| 参数 | 类型 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| id | integer | 配置 ID |
|
|
|
+
|
|
|
## 错误响应
|
|
|
|
|
|
所有错误响应格式:
|
|
|
@@ -265,6 +369,51 @@ API 已启用 CORS,支持跨域请求。
|
|
|
| 等待权限 | permission | AI 向用户申请权限 |
|
|
|
| 错误 | error | 会话错误 |
|
|
|
|
|
|
+## BLE 蓝牙推送说明
|
|
|
+
|
|
|
+配置 BLE 后,监控到状态变化时会自动通过蓝牙发送到设备。BLE 中继已嵌入 Go 二进制,无需额外文件或 Python 环境。
|
|
|
+
|
|
|
+### 构建含 BLE 的版本
|
|
|
+
|
|
|
+```bash
|
|
|
+# 一键构建(打包 Python 脚本 + 嵌入 Go 二进制)
|
|
|
+make build-with-ble
|
|
|
+
|
|
|
+# 或手动两步
|
|
|
+scripts\build_ble_relay.bat
|
|
|
+go build -tags ble -o bin/opencode-monitor.exe ./cmd/monitor
|
|
|
+```
|
|
|
+
|
|
|
+### Python 依赖(仅开发时需要)
|
|
|
+
|
|
|
+```bash
|
|
|
+pip install -r scripts/requirements.txt
|
|
|
+```
|
|
|
+
|
|
|
+### 状态映射
|
|
|
+
|
|
|
+| Go 状态码 | 蓝牙模式 | 说明 |
|
|
|
+|-----------|---------|------|
|
|
|
+| idle | idle | 空闲 |
|
|
|
+| busy | busy | 工作中 |
|
|
|
+| retry | thinking | 重试中 |
|
|
|
+| pending | thinking | 等待/修改中 |
|
|
|
+| reasoning | thinking | 思考中 |
|
|
|
+| using_tool | ai | 使用工具 |
|
|
|
+| running | ai | 工具运行中 |
|
|
|
+| completed | success | 完成 |
|
|
|
+| session_completed | success | 会话完成 |
|
|
|
+| permission | alarm | 等待权限 |
|
|
|
+| error | error | 错误 |
|
|
|
+
|
|
|
+### Python 依赖(仅 Python 方式需要)
|
|
|
+
|
|
|
+```bash
|
|
|
+pip install -r scripts/requirements.txt
|
|
|
+```
|
|
|
+
|
|
|
+如果使用预编译二进制则不需要安装。
|
|
|
+
|
|
|
## WebSocket 实时状态
|
|
|
|
|
|
启动监控服务后,可以通过浏览器访问 `http://localhost:8080` 查看实时状态页面。
|