OpenThread 移植 OpenWrt:RCP + otbr-agent 最小路径
一句话:不是“移植协议栈”,而是 RCP 射频固件 + OpenWrt 主机侧
openthread-br+ netifd 集成。
先分清两个角色
Thread 设备需要 802.15.4 射频;OpenWrt 路由器通常没有。
所以常见架构是:
802.15.4 射频 MCU(RCP 固件)
│ UART/USB,Spinel/HDLC
OpenWrt(otbr-agent + netifd proto openthread)
│ IPv6
LAN / Wi-Fi / 上行
- RCP:Radio Co-Processor,只负责 802.15.4 收发;
- otbr-agent:跑在 OpenWrt 上,负责 Thread 协议栈、边界路由;
- Spinel/HDLC:主机和 RCP 之间的控制协议。
不是把 OpenThread 直接塞进 OpenWrt 内核,也不是用 Wi-Fi/蓝牙模拟 802.15.4。
1. 准备 RCP 硬件
需要支持 OpenThread RCP 的 802.15.4 射频,例如:
- Nordic nRF52840 USB dongle(OpenWrt
openthread-br包测试过); - Silicon Labs EFR32MG24/MG26(刷 ot-rcp 固件);
- TI CC2652 等支持 RCP 的模组。
烧好 RCP 固件后,确认设备节点:
ls /dev/ttyACM* /dev/ttyUSB*
常见是 /dev/ttyACM0 或 /dev/ttyUSB0。
RCP 固件不在 OpenWrt 包里,需要按射频厂商的方式单独编译/烧录。
2. OpenWrt 侧用现成包
OpenWrt packages feed 里已经有:
net/openthread-br
优先用它,不要从零搬 OpenThread 源码。
需要 LuCI 的话:
luci-app-openthread
注意:LuCI 应用已经不在 openthread-br 包里,需要单独的 luci-app-openthread,而且 feed 要足够新。
小 flash 设备通常装不下,别在 16MB 以下设备上硬塞。
3. 配置 UCI
在 /etc/config/network 加:
config interface 'thread'
option device 'wpan0'
option proto 'openthread'
option backbone_network 'lan'
option radio_url 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=460800'
list prefix 'fd6f:5772:5468:7200::/64 paros'
option verbose '0'
必需项:
| 选项 | 作用 |
|---|---|
device 'wpan0' | Thread 网络接口名 |
proto 'openthread' | 交给 OpenThread proto handler |
backbone_network 'lan' | 上行 backbone 接口 |
radio_url | RCP 串口和波特率 |
backbone_network 必须指向真实存在的接口,否则会报:
"errors": [
{"subsystem": "openthread", "code": "MISSING_BACKBONE_NETWORK"}
]
4. 启动和检查
ifup thread
ifstatus thread
otbr-agent 由 netifd 拉起,不是普通 init 脚本直接管理。
首次建网前,先停掉自动启动的 Thread:
ubus call otbr threadstop
5. 建 Thread 网络
ot-ctl dataset init new
ot-ctl dataset panid 0x12ab
ot-ctl dataset extpanid 12ab12ab12ab12ab
ot-ctl dataset networkname OpenWrThread
ot-ctl dataset networkkey ddf429af1c52d1735ffaf36fae343ee8
ot-ctl dataset commit active
ot-ctl ifconfig up
ot-ctl thread start
ot-ctl netdata register
检查状态:
ot-ctl state
ot-ctl ipaddr
ot-ctl netdata show
6. 给 Thread 前缀加路由
主路由器需要知道 Thread 网段怎么走,否则设备入网会失败。
取前缀:
ot-ctl prefix
例如:
fd6b:a92f:c531:1::/64 paros low f000
在上级路由器上加到这个前缀的路由,指向 OpenWrt 的 LAN 地址。
7. 导出 dataset 给设备入网
ot-ctl dataset active -x
输出的十六进制 TLV 用于 Matter/Thread 设备入网。
不要把它随便发到公开渠道:里面包含网络密钥。
8. 加入已有 Thread 网络
如果已有 Border Router,直接用 active dataset:
config interface 'thread'
option device 'wpan0'
option proto 'openthread'
option backbone_network 'lan'
option dataset '0e080000...'
option radio_url 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=460800'
option verbose '0'
然后:
ifup thread
ot-ctl state
常见坑
- 没有 802.15.4 射频:Wi-Fi/蓝牙模块不能替代。
- RCP 固件不匹配:主机和 RCP 的 Spinel 版本要兼容。
- radio_url 写错:设备节点、波特率、
spinel+hdlc+uart前缀都要对。
- backbone_network 不存在:先
ifstatus lan确认。
- prefix 路由没加:设备能入网但跨网段不通。
- dataset 泄露:等于泄露 Thread 网络密钥。
- 小 flash 硬装:依赖和二进制放不下,先看空间。
- 用错包:先查
openthread-br,不要自己搬整个协议栈。
Q&A
Q1. 这是把 OpenThread 移植到 OpenWrt 吗?
不是传统意义上的源码移植,主要是 RCP 固件 + openthread-br 包 + netifd 配置。
Q2. 没有 802.15.4 射频能做吗?
不能做真实 Thread 网络。可以用模拟器学习,但不能替代硬件。
Q3. 一定要 nRF52840 吗?
不是。它只是 OpenWrt 包测试过的方案;EFR32、CC2652 等 RCP 也可以,但要自己保证固件兼容。
Q4. otbr-agent 谁启动?
netifd 通过 proto openthread 启动。
Q5. Thread 设备入网需要什么?
active operational dataset,通常用 ot-ctl dataset active -x 导出。
Q6. 为什么设备入网后跨网段不通?
上级路由器没有到 Thread prefix 的路由。
Q7. 可以跑在 OpenWrt 路由器上吗?
可以,但需要射频 RCP + 足够 flash/内存;不是所有路由器都适合。
Q8. 和 Wi-Fi Mesh 是一回事吗?
不是。Thread 基于 802.15.4,低功耗 Mesh;Wi-Fi 是另一套链路。
相关:OpenWrt 与 prplOS · VLAN 与网桥
评论 0
还没有评论,来抢沙发~