Bt¶
- 描述
1)型号:AP6275S模块,支持蓝牙和Wi-Fi同时使用 2)节点名称:在Linux系统中,蓝牙设备通常被标识为hciX,其中X是一个数字,表示不同的蓝牙控制器。HCI代表“Host Controller Interface”,它是主机与蓝牙硬件之间的接口。 HCI是蓝牙协议栈的一部分,负责处理主机与蓝牙硬件之间的通信。 3)工具 hciattach hciconfig hcitool 编译选项:BR2_PACKAGE_BLUEZ5_UTILS
- 服务说明
sdptool browse local | grep Name Service Name: Generic Access Profile Service Name: Generic Attribute Profile Service Name: AVRCP CT Service Name: AVRCP TG 1. Generic Access Profile (GAP):这是蓝牙协议栈中的一个基本配置文件,负责设备的发现和连接。 2. Generic Attribute Profile (GATT):这是用于 BLE 设备的主要配置文件,允许设备之间通过特征和服务进行数据交换。 3. AVRCP CT 和 AVRCP TG:这些是音频/视频远程控制配置文件,主要用于控制音频/视频设备的播放。
- 工具
# apt install bluez hciconfig hcitool hciattach hcidump bluetoothctl bluetoothd obexctl obexd rfcomm sdptool gatttool btmon # 跨平台BLE调试工具: nrf-connect https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-desktop
- 查看蓝牙设备
hcitool dev
- 查看蓝牙名字
hciconfig hci0 name
- 重命名蓝牙
hciconfig hci0 name "新名称" 注:默认的蓝牙名称可尝试在 /etc/bluetooth/main.conf 里设置
- 初始化蓝牙
./bt_pcba_test
- 打开蓝牙
hciconfig hci0 up hciconfig -a
hci0: Type: Primary Bus: UART BD Address: 08:FB:EA:1A:90:07 ACL MTU: 1021:8 SCO MTU: 64:1 UP RUNNING RX bytes:2824 acl:0 sco:0 events:84 errors:0 TX bytes:4125 acl:0 sco:0 commands:73 errors:0 Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 Link policy: RSWITCH SNIFF Link mode: SLAVE ACCEPT Name: 'LPA3588' Class: 0x100000 Service Classes: Object Transfer Device Class: Miscellaneous, HCI Version: 5.1 (0xa) Revision: 0x17 LMP Version: 5.1 (0xa) Subversion: 0x1111 Manufacturer: Broadcom Corporation (15)
- 扫描蓝牙设备
hcitool scan
- 查看蓝牙设备信息
hcitool info XX:XX:XX:XX:XX:XX
- 设置蓝牙可被发现
hciconfig hci0 piscan
- 设置蓝牙不可被发现
hciconfig hci0 noscan
- 重置蓝牙
hciconfig hci0 reset
- 关闭蓝牙
hciconfig hci0 down
- bluetoothctl(apt install bluez,安装后会有一个bluetoothd守护进程)
# 进入bluetoothctl命令行 bluetoothctl # 进入bluetoothctl命令行后,类似:[bluetooth]# # Controller代表arm板上的蓝牙设备,Device代表蓝牙耳机 # 按如下步骤初始化蓝牙设备,并连接蓝牙耳机 # 查看帮组 help power on agent on default-agent # 启动扫描 scan on # 蓝牙设备标记为受信任,以后连接该设备时,就不需要每次都手动确认连接 trust 04:8C:9A:F2:54:4B # 配对 pair 04:8C:9A:F2:54:4B # 连接 connect 04:8C:9A:F2:54:4B # 查看蓝牙耳机信息 info 04:8C:9A:F2:54:4B # 断开连接 disconnect 04:8C:9A:F2:54:4B # 不想自动连接上蓝牙耳机,可以删除配对信息 remove 04:8C:9A:F2:54:4B # 设置设备可被发现 discoverable on/off # 查看已配对设备 paired-devices # 退出 exit/quit # 可以以命令的形式执行 bluetoothctl paired-devices
- 添加SPP服务
sdptool add SP sdptool browse local 注:Failed to connect to SDP server on FF:FF:FF:00:00:00: No such file or directory 解决:修改系统中蓝牙服务的启动选项,-C的意思就是compat,兼容性模式运行蓝牙服务 sudo vim /lib/systemd/system/bluetooth.service ExecStart=/usr/lib/bluez5/bluetooth/bluetoothd -C 重启服务: systemctl daemon-reload systemctl restart bluetooth.service
- GATT服务
gatttool -b XX:XX:XX:XX:XX:XX -I # -b 对端蓝牙地址,-I 表示以交互模式启动
- 其它
# 认证打开/关闭,直接体现在进行蓝牙连接时,是否输入连接PIN密码,用于PIN配对: hciconfig hci0 auth/noauth # 查看/改变蓝牙主从状态: hciconfig hci0 lm master(改为主模式) hciconfig hci0 lm slave(改为从模式) # 查看HCI设备信息: hcitool dev # 发现周围蓝牙设备: hcitool -i hci0 inq # 蓝牙扫描: hcitool -i hci0 inq # 查看探查到的蓝牙信息: hcitool -i hci0 name 88:A9:B7:E6:F1:8F # 发送CMD蓝牙命令: hcitool cmd --help
- 示例
bluetoothctl power on agent on discoverable on
- 参考
https://doc.embedfire.com/linux/rk3588/quick_start/zh/latest/quick_start/wireless/bluetooth/bluetooth.html https://blog.csdn.net/chenjk10/article/details/90317028 https://www.bilibili.com/video/BV1Y24y1A7xH/ rk3588平台AP6275S蓝牙模块开发调试(重要): https://blog.csdn.net/quququuquq/article/details/131805413 EC-A1684JD4 蓝牙音频/文件收发: https://wiki.t-firefly.com/EC-A1684JD4/usage_bt.html#yin-pin-ce-shi