Type-safe, high-performance, secure RPC over Bluetooth Low Energy.
Protocol Buffers
使用 .proto 文件定义 BLE 通信。获得类型安全、语言无关的序列化,消除一切歧义
高性能
通过 MTU 感知的分片和零拷贝优化,实现接近 BLE 最大吞吐量(约 30 KB/s)
端到端加密
可选的端到端加密,采用 X25519 密钥交换、Ed25519 签名和 AES-128-GCM 会话加密
工作原理
bleRPC 在 BLE GATT 之上提供分层协议栈:
- 命令层 — 使用命令元数据(名称、类型、数据长度)包装 Protocol Buffers 载荷
- 加密层(可选)— 在4 步密钥交换后使用 AES-128-GCM 加密序列化的命令
- 容器层 — 将载荷分片为 MTU 大小的容器进行 BLE 传输,并在接收端重新组装
所有通信使用单个 GATT Characteristic:Central 通过 Write Without Response 写入请求,并通过 Notify 接收响应。
sequenceDiagram
participant C as Central<br/>(iOS / Android / Flutter / RN / Python)
participant P as Peripheral<br/>(Zephyr / Python)
Note over C: Protobuf encode + Command wrap
Note over C: Encrypt (if enabled)
Note over C: Split into MTU containers
C->>+P: Write Without Response (containers)
Note over P: Reassemble containers
Note over P: Decrypt (if enabled)
Note over P: Decode command + Protobuf
Note over P: Execute handler
Note over P: Encode response + Encrypt + Split
P->>-C: Notify (containers)
Note over C: Reassemble + Decrypt + Decode
支持的平台
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) |