本项目提供一个基于 Flask 的 HTTP API 与网页界面,用于控制展品 LED 灯效与 Kodi 播放。
安装依赖
pip install -r requirements.txt
bash
python flask_api.py
或双击 start_server.bat
http://localhost:5000success:布尔,是否成功message:字符串,结果说明data:对象,可选,承载具体数据/
templates/index.html 页面GET /api/led/status
成功响应示例:
{
"success": true,
"data": {
"is_running": true,
"message": "灯效正在运行"
}
}
/api/led/startjson
{ "exhibit_id": 0 }
校验:exhibit_id 必须为大于等于 0 的整数
成功响应示例:
{
"success": true,
"message": "展品 0 的灯效已启动",
"data": { "exhibit_id": 0, "is_running": true }
}
/api/led/stopjson
{ "success": true, "message": "灯效已停止", "data": { "is_running": false } }
GET /api/kodi/status
成功响应示例:
{
"success": true,
"data": {
"is_running": false,
"message": "Kodi播放线程已停止"
}
}
/api/kodi/startvideo_idjson
{ "video_id": 1 }
校验:video_id 必须为大于等于 0 的整数
成功响应示例:
{ "success": true, "message": "Kodi开始/切换播放 视频ID=1", "data": { "video_id": 1 } }
/api/kodi/stopjson
{ "success": true, "message": "Kodi播放已停止" }
参数缺失/非法:HTTP 400
示例:
{ "success": false, "message": "缺少展品ID参数" }
json
{ "success": false, "message": "启动灯效失败: error detail" }
# LED 状态
curl -s http://localhost:5000/api/led/status | jq
# 启动 LED(展品ID=0)
curl -s -X POST http://localhost:5000/api/led/start \
-H "Content-Type: application/json" \
-d '{"exhibit_id": 0}' | jq
# 停止 LED
curl -s -X POST http://localhost:5000/api/led/stop | jq
# Kodi 状态
curl -s http://localhost:5000/api/kodi/status | jq
# 启动/切换 Kodi(视频ID=1)
curl -s -X POST http://localhost:5000/api/kodi/start \
-H "Content-Type: application/json" \
-d '{"video_id": 1}' | jq
# 停止 Kodi
curl -s -X POST http://localhost:5000/api/kodi/stop | jq
LEDEffectFramework_V1/
├── flask_api.py # Flask API 入口
├── application/
│ ├── wled_thread.py # LED 业务逻辑入口
│ └── kodi_thread.py # Kodi 业务逻辑入口
├── hardware/ # 硬件/控制模块
├── templates/
│ └── index.html # 网页界面
├── requirements.txt
├── start_server.bat
└── README_API.md
flask_api.py 中配置,默认 0.0.0.0:5000application/* 与 hardware/* 实现