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

依赖安装

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                                      Select default controller
devices                                           List available devices
paired-devices                                    List paired devices
system-alias                                Set controller alias
reset-alias                                       Reset controller alias
power                                     Set controller power
pairable                                  Set controller pairable mode
discoverable                              Set controller discoverable mode
agent                          Enable/disable agent with given capability
default-agent                                     Set agent as the default one
advertise                            Enable/disable advertising with given type
set-alias                                  Set device alias
scan                                      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                                       Remove device
connect                                      Connect device
disconnect [dev]                                  Disconnect device
menu                                        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

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

你可能感兴趣的:(树莓派命令行连接蓝牙音响)