树莓派3 蓝牙的配置

                                                                                        树莓派3 蓝牙的配置


参考网址:https://github.com/ev3dev/ev3dev/issues/198

http://blog.csdn.net/Aguangg_6655_la/article/details/54637165

https://wiki.archlinux.org/index.php/Bluetooth_headset#A2DP_via_Bluez5.2FPulseaudio


一、前言

说实话,配置树莓派3的蓝牙功能,简直配置的心力交瘁,查了无数资料,话不多说了

直接进去正题


二、蓝牙配置

1、先更新源,用阿里的源比较快

deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main contrib non-free rpi

sudo apt-get update
sudo apt-get updgrade -y
sudo apt-get dist-upgrade -y


2、安装依赖包

sudo apt-get install pi-bluetooth bluez bluez-firmware blueman


3、下载好后,将pi用户添加到蓝牙组

sudo usermod -G bluetooth -a pi


4、启动服务,重启树莓派

sudo systemctl start bluetooth
sudo reboot


三、蓝牙连接

1、开启蓝牙

sudo systemctl start bluetooth


2、配对某个设备(注意是root权限)

sudo bluetoothctl

[bluetooth]# scan on

[bluetooth]# agent on
[bluetooth]# trust xx:xx:xx:xx:xx:xx
[bluetooth]# pair xx:xx:xx:xx:xx:xx
[bluetooth]# connect xx:xx:xx:xx:xx


3、查看蓝牙工作状态
systemctl status bluetooth


4、如果能成功连接,如果不能,请看第四部分


四、异常处理,这才是关键

以下未经说明都是以root权限运行


1、查看异常一定要记住查看日志

查看系统日志:  journalctl -n 20

里面记录了出现了何种异常


2、先按照我认为能让蓝牙工作的流程配置一下

1)安装相关模块: 

apt-get install --no-install-recommends pulseaudio pulseaudio-module-bluetooth


2)下载2个配置文件: 

https://gist.github.com/dlech/7e9d28bccac9632cbc50#file-pulseaudio-service


3)配置配置文件

cp pulseaudio.service   /etc/systemd/system/

systemctl daemon-reload

cp pulseaudio-bluetooth.conf   /etc/dbus-1/system.d/


4)修改相关配置文件

打开配置文件,最下面行加入:

vim /etc/pulse/system.pa

### Automatically load driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif


.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif


5)将root 和 pi 加入 audio pulse-access 族

usermod -a -G pulse-access,audio  root

usermod -a -G pulse-access,audio  pi


6)启动服务:systemctl start pulseaudio.service


7)查看系统日志,是否有异常

(1)、出现下面这些错误,忽略

pulseaudio[18912]: E: [pulseaudio] bluez4-util.c: org.bluez.Manager.GetProperties() failed: org.freedesktop.DBus.Error.UnknownMethod: Method "GetProperties"


xcb_connection_has_error() returned true


8)登录pulse

su -s /bin/bash pulse

pactl list | grep Card 


如果只连接一个蓝牙设备,标签1就是,看具体情况

Card #1
    Name: bluez_card.00_17_E7_BD_1C_8E
    Driver: module-bluez5-device.c
    Owner Module: 14
    Properties:
        device.description = "BlueZ 5.23"
        device.string = "00:17:E7:BD:1C:8E"
        device.api = "bluez"
        device.class = "sound"
        device.bus = "bluetooth"
        bluez.path = "/org/bluez/hci0/dev_00_17_E7_BD_1C_8E"
        bluez.class = "0x0c0000"
        bluez.alias = "BlueZ 5.23"
        device.icon_name = "audio-card-bluetooth"
    Profiles:
        a2dp_source: High Fidelity Capture (A2DP Source) (sinks: 0, sources: 1, priority: 10, available: yes)
        a2dp: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
        off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
    Active Profile: a2dp
    Ports:
        unknown-output: Bluetooth Output (priority: 0, latency offset: 0 usec)
            Part of profile(s): a2dp
        unknown-input: Bluetooth Input (priority: 0, latency offset: 0 usec)
            Part of profile(s): a2dp_source


9)、将蓝牙设备设置为a2dp模式

pactl set-card-profile 1 a2dp 


10)可以用mplayer 播放音乐测试了

(1)、播放音乐

(2)、win远程桌面->sound -> pulseAudio ->fallback -> audio stream ->蓝牙设备


11)查看系统日志,如果出现其他的异常,自己百度吧


猜你喜欢

转载自blog.csdn.net/wangdamingll/article/details/77587541