Files
2025-08-09 23:56:21 +08:00

48 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 心率监测 WebSocket 服务
这是一个基于ASP.NET Core的WebSocket服务用于接收心率监测设备的数据并转发给其他连接的客户端。
## 功能
- 接收心率数据(包含心率值、时间戳和设备名称)
- 验证客户端Token确保安全性
- 向其他所有已连接的客户端广播心率数据不包含Token
## 技术栈
- ASP.NET Core 9.0
- WebSockets
- System.Text.Json
## 数据格式
### 接收的数据格式
```json
{
"heartRate": 75,
"timestamp": "2023-04-10T15:30:45.123Z",
"deviceName": "HeartMonitor-X1",
"token": "token.txt"
}
```
token是鉴权的唯一方式请自行在程序主目录添加token.txt并填入token
### 广播的数据格式
```json
{
"heartRate": 75,
"timestamp": "2023-04-10T15:30:45.123Z",
"deviceName": "HeartMonitor-X1"
}
```
## 使用方式
1. 在程序主目录创建 `token.txt` 文件并填入一个有效的Token。
2. 启动服务。
3. 通过WebSocket连接到 `ws://localhost:5000/ws``wss://localhost:5001/ws`
4. 发送包含有效Token的心率数据JSON
5. 接收来自其他客户端的心率数据广播