Apache-2.0 · 开源

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 之上提供分层协议栈:

  1. 命令层 — 使用命令元数据(名称、类型、数据长度)封装 Protocol Buffers 载荷
  2. 加密层(可选)— 在完成4 步密钥交换后,使用 AES-128-GCM 对序列化后的命令进行加密
  3. 容器层 — 将载荷分片为 MTU 大小的容器进行 BLE 传输,并在接收端重新组装

所有通信使用单个 GATT Characteristic:中心设备(Central)通过 Write Without Response 发送写入请求,并通过 Notify 接收响应。

阅读完整协议规范 →

Benchmarks

真实吞吐量

在启用端到端加密(AES-128-GCM)、MTU 247 的 nRF54L15 DK 外设上实测 — 闪存读取吞吐量。

Android
59.0 KB/s
iOS
32.1 KB/s
Python
30.3 KB/s

查看完整基准测试结果 →

Ecosystem

支持的平台

Central(客户端)

平台语言BLE 协议栈状态
iOSSwiftCoreBluetooth稳定
AndroidKotlinAndroid BLE稳定
iOS / AndroidDart (Flutter)flutter_blue_plus稳定
iOS / AndroidTypeScript (React Native)react-native-ble-plx稳定
macOS / LinuxPythonbleak稳定
Zephyr (nRF54L15)CZephyr BLE稳定

Peripheral(服务端)

平台语言BLE 协议栈状态
Zephyr (nRF54L15)CZephyr BLE稳定
Zephyr (EFR32xG22E)CZephyr BLE + SiLabs HCI稳定
macOSPythonbless稳定

协议库

语言依赖
Swiftblerpc-protocol-swiftFoundation + CryptoKit
Kotlinblerpc-protocol-ktProtobuf JavaLite
Dartblerpc-protocol-dartcryptography
Pythonblerpc-protocolcryptography
TypeScriptblerpc-protocol-rn@noble/ciphers + @noble/curves + @noble/hashes
Cblerpc-protocol/c无(Zephyr 上使用 PSA Crypto)

立即构建你的设备 API

阅读协议规范,接入客户端,几分钟内即可与硬件通信