Apache-2.0 · 开源
Type-safe RPC over
Type-safe RPC over
Bluetooth Low Energy
只需用 Protocol Buffers 定义一次设备 API,bleRPC 即可为六大平台生成类型安全的客户端与处理程序,内置自适应 MTU 分片和可选的端到端加密。
blerpc.proto
message EchoRequest { string message = 1; }
message EchoResponse { string message = 1; }
↓ 自动发现 echo 命令
let client = BlerpcClient()
try await client.connect(device: devices[0])
let res = try await client.echo(message: "hello")
print(res.message) // "hello"val client = BlerpcClient(context)
client.connect(devices[0])
val res = client.echo(message = "hello")
println(res.message) // "hello"final client = BlerpcClient();
await client.connect(devices[0]);
final res = await client.echo(message: 'hello');
print(res.message); // "hello"const client = new BlerpcClient()
await client.connect(devices[0])
const res = await client.echo({ message: 'hello' })
console.log(res.message) // "hello"client = BlerpcClient()
await client.connect(devices[0])
resp = await client.echo(message="hello")
print(resp.message) # "hello"blerpc_EchoResponse resp;
int ret = blerpc_echo("hello", &resp);
if (ret == 0)
printk("%s\n", resp.message); // "hello"6
平台
59 KB/s
吞吐量
20 B
加密开销
AES-128-GCM
端到端加密
Features
Protocol Buffers
使用 .proto 文件定义 BLE 通信。获得类型安全、语言无关的序列化,确保无歧义
高性能
通过自适应 MTU 分片和零拷贝优化充分利用 BLE 带宽,实测最高约 59 KB/s(Android)
端到端加密
可选的端到端加密,采用 X25519 密钥交换、Ed25519 签名和 AES-128-GCM 会话加密
Architecture
工作原理
bleRPC 在 BLE GATT 之上提供分层协议栈:
- 命令层 — 使用命令元数据(名称、类型、数据长度)封装 Protocol Buffers 载荷
- 加密层(可选)— 在完成4 步密钥交换后,使用 AES-128-GCM 对序列化后的命令进行加密
- 容器层 — 将载荷分片为 MTU 大小的容器进行 BLE 传输,并在接收端重新组装
所有通信使用单个 GATT Characteristic:中心设备(Central)通过 Write Without Response 发送写入请求,并通过 Notify 接收响应。
Benchmarks
真实吞吐量
在启用端到端加密(AES-128-GCM)、MTU 247 的 nRF54L15 DK 外设上实测 — 闪存读取吞吐量。
Ecosystem
支持的平台
Central(客户端)
| 平台 | 语言 | BLE 协议栈 | 状态 |
|---|---|---|---|
| iOS | Swift | CoreBluetooth | 稳定 |
| Android | Kotlin | Android BLE | 稳定 |
| iOS / Android | Dart (Flutter) | flutter_blue_plus | 稳定 |
| iOS / Android | TypeScript (React Native) | react-native-ble-plx | 稳定 |
| macOS / Linux | Python | bleak | 稳定 |
| Zephyr (nRF54L15) | C | Zephyr BLE | 稳定 |
Peripheral(服务端)
| 平台 | 语言 | BLE 协议栈 | 状态 |
|---|---|---|---|
| Zephyr (nRF54L15) | C | Zephyr BLE | 稳定 |
| Zephyr (EFR32xG22E) | C | Zephyr BLE + SiLabs HCI | 稳定 |
| macOS | Python | bless | 稳定 |
协议库
| 语言 | 包 | 依赖 |
|---|---|---|
| Swift | blerpc-protocol-swift | Foundation + CryptoKit |
| Kotlin | blerpc-protocol-kt | Protobuf JavaLite |
| Dart | blerpc-protocol-dart | cryptography |
| Python | blerpc-protocol | cryptography |
| TypeScript | blerpc-protocol-rn | @noble/ciphers + @noble/curves + @noble/hashes |
| C | blerpc-protocol/c | 无(Zephyr 上使用 PSA Crypto) |
立即构建你的设备 API
阅读协议规范,接入客户端,几分钟内即可与硬件通信