树莓派命令行连接蓝牙音响

依赖安装

sudo apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2 bluez-tools

命令行连接蓝牙

# 打开蓝牙进入命令模式
sudo bluetoothctl

# 查看所有命令
[bluetooth]# help
Menu main:
Available commands:
-------------------
advertise                                         Advertise Options Submenu
scan                                              Scan Options Submenu
gatt                                              Generic Attribute Submenu
list                                              List available controllers
show [ctrl]                                       Controller information
select <ctrl>                                     Select default controller
devices                                           List available devices
paired-devices                                    List paired devices
system-alias <name>                               Set controller alias
reset-alias                                       Reset controller alias
power <on/off>                                    Set controller power
pairable <on/off>                                 Set controller pairable mode
discoverable <on/off>                             Set controller discoverable mode
agent <on/off/capability>                         Enable/disable agent with given capability
default-agent                                     Set agent as the default one
advertise <on/off/type>                           Enable/disable advertising with given type
set-alias <alias>                                 Set device alias
scan <on/off>                                     Scan for devices
info [dev]                                        Device information
pair [dev]                                        Pair with device
trust [dev]                                       Trust device
untrust [dev]                                     Untrust device
block [dev]                                       Block device
unblock [dev]                                     Unblock device
remove <dev>                                      Remove device
connect <dev>                                     Connect device
disconnect [dev]                                  Disconnect device
menu <name>                                       Select submenu
version                                           Display version
quit                                              Quit program
exit                                              Quit program
help                                              Display help about this program
export                                            Print evironment variables

# 打开蓝牙
[bluetooth]# power on
Changing power on succeeded

# 打开代理
[bluetooth]# agent on
Agent is already registered

# 搜索可用蓝牙设备
[bluetooth]# scan on

# 查看可用蓝牙列表
[bluetooth]# devices
Device B8:18:54:02:4A:FF BT5.0 KB
Device 00:1A:7D:DA:71:11 DESKTOP-NRJSO9Q
Device 6B:2F:AB:45:4E:D2 BT5.0 KB
Device 10:9E:3A:37:8E:17 方糖(2E:21)
Device 8E:65:6C:20:DF:E1 BT5.0 KB
Device 12:34:30:03:6D:F7 BT3.0 Keyboard
Device C2:5E:49:3C:92:A2 BT5.0 KB
Device 5C:1D:D9:61:0F:AA iPhone
Device 30:35:AD:AA:FE:4F 30-35-AD-AA-FE-4F
Device 6E:80:06:FD:33:F5 6E-80-06-FD-33-F5

# 连接方糖
[bluetooth]# pair 10:9E:3A:37:8E:17
[bluetooth]# trust 10:9E:3A:37:8E:17
[bluetooth]# connect 10:9E:3A:37:8E:17

# 退出蓝牙命令模式
[bluetooth]# exit

这样即可完成树莓派连接蓝牙音响

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。