For miband 4~7, checkout
miband-4-to-7tag对于小米手环 4~7,请切换到
miband-4-to-7标签
Real-time heart rate monitoring for Xiaomi Smart Bands via BLE, with a web dashboard, persistent history, and automatic reconnection.
通过 BLE 接收小米手环心率广播数据,提供 Web 仪表盘实时显示、历史记录查询和断线自动重连。
- 实时心率监控 — 通过 BLE 接收手环”运动心率广播”数据
- Web 仪表盘 —
http://127.0.0.1:8765实时动态心率 + 心跳动画 - 历史分析面板 —
/history查看趋势图、心率区间分布、应用窗口统计 - SQLite 持久化 — 心率数据自动存入数据库,支持按天/周/月查询
- 窗口追踪 — 记录每个心率值对应的前台窗口和进程名称
- SSE 实时推送 — Server-Sent Events 推送到前端,无需轮询
- 断线自动重连 — 15s 超时检测静默断连 + 指数退避重连(2s→60s)
- 补偿式退避 — 重连失败后间隔逐步增大,成功后立即重置
基于 bluest 跨平台 BLE 库:
Bluest is a cross-platform Bluetooth Low Energy (BLE) library for Rust. It currently supports Windows (version 10 and later), MacOS/iOS, and Linux. Android support is planned.
- Windows 10/11
- MacOS/iOS
- Linux
| 型号 | 状态 |
|---|---|
| Xiaomi Smart Band 9 Pro | ✅ 已测试 |
| MiBand 10 / NFC | ✅ 已测试 |
| MiBand 4~7 | 切换到 miband-4-to-7 标签 |
- 在手环设置中开启心率广播功能
- 电脑支持 BLE(蓝牙低功耗)
cargo run --release打开浏览器访问:
- 实时仪表盘:
http://127.0.0.1:8765 - 历史分析:
http://127.0.0.1:8765/history
| 端点 | 说明 |
|---|---|
/ |
实时心率仪表盘 |
/history |
历史数据分析面板 |
/events |
SSE 事件流(实时心率推送) |
/api/records?range=today|7d|30d |
JSON 心率记录 |
/api/stats?range=today|7d|30d |
JSON 统计摘要 |
/api/recent?limit=50 |
JSON 最近记录 |
