穿越机配置工具
目前,市面上连接BetaFlight给飞控固件调参比较顺手的工具大体上是官网的BetaFlight Configurator(国内都叫BF地面站,其实个人感觉不应该叫地面站,配置工具更好。因为地面站更多具有导航,航线规划和控制功能)。
除此之外,比较能够让大家耳目一新的大概是手机端的SpeedyBee这应用软件,非常适合场外进行参数调整。
所以开源的东西就是香,大体的意思就是免费,还专业。
本文的主要目的是期望在开源项目基础上,尤其通过其协议接口进行配置工具对接,摆脱有线连接的困扰。为后续MSP协议的相关控制奠定基础。
本次验证主要基于蓝牙,通过BLE SPP 或者BT SPP 对飞控串口RxTx进行无线扩展连接。
软件:SpeedyBee APP v1.8.0
固件:BleSppUart
参考视频:
ESP32 BLE SPP server 範例,並連接到手機上,傳送訊息。
存在问题:
a) BLE 默认MTU大小23字节。当报文超过该长度(含报文头,占4字节),将会采取分包。
b) BLE分包格式:分包头 + payload鉴于Windows/手机上没有BLE SPP标准虚拟串口驱动模型,因此在实现组包和分包头解析可能存在应用上的设计差异。
实测结果
a) SpeedyBee认识短包(无需分包+组包过程)
b) SpeedyBee无法识别长包(需要分包组包过程)SpeedyBee无法通过BleSppUart连接BF飞控。所以App上所说的Bluetooth-UART Adapter(通用的模块是硬件,固件必须使用SpeedyBee厂家,有报文解析方面自定义内容)。
注:若有同学知道这个协议格式,或者哪里可以搜到,也请告知!我没有找到,也许是他们闭源的原因。
日志分析
前面三个命令UUI, API version and FC version成功,整体没有超过23字节(MTU),获取BUILD_INFO指令反馈32字节,需要两个20字节分组报文。App似乎一直没有拿到这些数据,所以尝试了7次以后就主动断掉BLE SPP。
99: I (35523) BleSppUart: BLE read 6 Bytes //UUID
124: I (37553) BleSppUart: BLE read 6 Bytes //UUID
141: I (37703) BleSppUart: BLE read 6 Bytes //API version
157: I (37793) BleSppUart: BLE read 6 Bytes // FC_VERSION
173: I (37943) BleSppUart: BLE read 6 Bytes // BUILD_INFO
202: I (39943) BleSppUart: BLE read 6 Bytes // BUILD_INFO
231: I (42043) BleSppUart: BLE read 6 Bytes // BUILD_INFO
260: I (44083) BleSppUart: BLE read 6 Bytes // BUILD_INFO
289: I (46133) BleSppUart: BLE read 6 Bytes // BUILD_INFO
318: I (48083) BleSppUart: BLE read 6 Bytes // BUILD_INFO
347: I (50133) BleSppUart: BLE read 6 Bytes // BUILD_INFO
搜索资料
两个TI方面的资料表明BLE SPP是自定义的,并非标准接口。
逻辑分析
换句话说,自定义协议必须C/S端同时完成,就像编解码一样,需要成对完成。
方式一:自定义协议在BLE SPP Device里面嵌入
手机APP或PC应用 – UART – BLE SPP Device (Client) – BLE wireless – BLE SPP Device(Server, UART port)
方式二: 自定义下一在BLE SPP Device和手机APP或PC应用上嵌入
手机APP或PC应用 – BLE wireless – BLE SPP Device(Server, UART port)
软件:BetaFlight v10.8.0
固件:BtSppUart
参考视频:
實現 ESP32 Bluetooth SPP -Serial Port Profile- 的連線
实测结果
非常成功!!!关键是BT SPP串口的Windows配置方法。
注1:实际Windows上使用SPP蓝牙驱动是比较麻烦的,而且并非所有的都能成功。详见:Windows Bluetooth Pairing for Devices Using SPP
注2:Betaflight手机APP和Windows应用目前官方的反馈应该是没有支持蓝牙SPP串口驱动的。详见: BT SPP device NOT found #3141
如果希望官网支持,并非不行,但是上述Feature就需要实现Configurator的相关代码。
验证步骤:
Step1: Windows系统–>蓝牙和其他设备,选择【添加蓝牙和其他设备】
Step2:Windows系统设置–>设备,选择【更多蓝牙选项】
Step3:点击【添加】,增加一个蓝牙串口
Step4:将我们自主模块上电,在添加对话框找到BtSppUart设备
注:这里可能名字有点差异,主要是代码和截图使用不一致导致,请根据实际情况判断。整体过程是正确的。
Step5:点击确定,添加蓝牙虚拟串口(请留意串口端口号)
Step6:在计算机管理工具里面,确认蓝牙虚拟串口设备添加情况(一次添加过以后,第二次无需添加会自动连接。)
Step7: 在BetaFlight Configurator里面选择蓝牙虚拟串口
Step8:效果如下,如果感觉速度慢,可以将打印去掉
【1】BetaFlight模块设计之三十二:MSP协议模块分析
【2】iNavFlight之MSP DJI协议分析
【3】iNavFlight之MSP DJI协议天空端请求报文
【4】iNavFlight之MSP DJI协议飞控端请求应答
【5】實現 ESP32 Bluetooth SPP -Serial Port Profile- 的連線
【6】ESP32 BLE SPP server 範例,並連接到手機上,傳送訊息
有不少朋友咨询怎么配置,感觉windows上很困难,我将整个过程的图都截取出来,供大家参考。
固件版本:SnapAirUnit_Factory_v0.1.ce83307-clean
Bluetooth SPP 连接方式详见:How to I connect a raw serial terminal to a bluetooth connection?
发现设备
配对设备
配对成功
进入bluetoothctl
工具界面
# sudo bluetoothctl
使用工具进行配对
# power on //Be sure that the bluetooth device is started
# agent on //start the agent that will "remember the pin" for rfcomm
# scan on //scan mode to find our device
# pair //pair the device
实例:
# sudo bluetoothctl
Agent registered
[CHG] Device C4:9D:ED:A7:BA:55 RSSI: -60
[CHG] Device 24:6F:28:B3:F3:1E RSSI: -64
[CHG] Device C4:9D:ED:A7:BA:55 RSSI: -61
[CHG] Device 24:6F:28:B3:F3:1E RSSI: -53
[DEL] Device 60:D4:E9:65:60:4C OPPO A8
[CHG] Device C4:9D:ED:A7:BA:55 RSSI: -65
[CHG] Device 24:6F:28:B3:F3:1E RSSI: -54
[bluetooth]# pair 24:6F:28:B3:F3:1E
Attempting to pair with 24:6F:28:B3:F3:1E
[CHG] Device 24:6F:28:B3:F3:1E Connected: yes
Request confirmation
[agent] Confirm passkey 960332 (yes/no): yes
[CHG] Device 24:6F:28:B3:F3:1E UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device 24:6F:28:B3:F3:1E ServicesResolved: yes
[CHG] Device 24:6F:28:B3:F3:1E Paired: yes
Pairing successful
[CHG] Device 24:6F:28:B3:F3:1E ServicesResolved: no
[CHG] Device 24:6F:28:B3:F3:1E Connected: no
[CHG] Device 24:6F:28:B3:F3:1E RSSI: -54
[CHG] Device C4:9D:ED:A7:BA:55 RSSI: -65
[CHG] Device C4:9D:ED:A7:BA:55 RSSI: -55
[CHG] Device 24:6F:28:B3:F3:1E RSSI: -54
注:Ctrl + D
退出bluetoothctl
工具界面。
清理所有相关进程
# sudo killall rfcomm
启动rfcomm0端口
# sudo rfcomm connect /dev/rfcomm0 24:6F:28:B3:F3:1E 1 &
这里就偷懒去刷iNav的固件了,总的来说这样MSP就能通信上了。
SnapAirUnit Hardware V1.0 (experimental)
Github: SnapAirUnit, 更多功能增加中,如需要相关测试硬件可以联系我!