2017-01-17 232 views
0

我知道这不是第一次问这个问题,但在尝试了一周之后我可以做的每件事情之后,我仍然遇到问题。 我试图连接到我的树莓派到BLE设备。我可以扫描它们,但不能连接到它们。连接BLE设备与Raspberry Pi 3 B

最后的解释,我已经随之而来的是这个问题的GitHub:https://github.com/ukBaz/python-bluezero/issues/30

这里是我所做的尝试更新的bluez,使这方面工作的所有命令。

###Install RASPBIAN JESSIE LITE 
2017-01-11-raspbian-jessie-lite.img 

###Updates 
$ sudo apt-get update 

$ sudo apt-get upgrade 

###Add libs 
$ sudo apt-get install bluetooth bluez-tools build-essential autoconf glib2.0 libglib2.0-dev libdbus-1-dev libudev-dev libical-dev libreadline-dev git 

###Get bluez-5.43 
$ wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.43.tar.xz 

$ tar xf bluez-5.43.tar.xz 

$ cd bluez-5.43 

###Patch bluez 
$ wget https://gist.github.com/pelwell/c8230c48ea24698527cd/archive/3b07a1eb296862da889609a84f8e10b299b7442d.zip 

$ unzip 3b07a1eb296862da889609a84f8e10b299b7442d.zip 

$ git apply -v c8230c48ea24698527cd-3b07a1eb296862da889609a84f8e10b299b7442d/* 

###Install bluez 
$ ./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-experimental --enable-maintainer-mode 

$ make -j 4 && sudo make install 

### Add to /etc/dbus-1/system.d/bluetooth.conf 
<!-- allow users of bluetooth group to communicate --> 
<policy group="bluetooth"> 
    <allow send_destination="org.bluez"/> 
</policy> 

$ sudo usermod -G bluetooth -a $USER 

$ sudo sed -i '/^ExecStart.*bluetoothd\s*$/ s/$/ --experimental/' /lib/systemd/system/bluetooth.service 

$ sudo systemctl daemon-reload 

$ sudo service bluetooth restart 

$ service bluetooth status 

$ sudo reboot 

$ sudo hcitool lescan 
     LE Scan ... 
     XX:XX:XX:XX:XX:XX (name) 

$ gatttool -b XX:XX:XX:XX:XX:XX -I 
     [XX:XX:XX:XX:XX:XX][LE]> connect 
     Attempting to connect to XX:XX:XX:XX:XX:XX 
     Error: connect error: Transport endpoint is not connected (107) 


$ gatttool -b XX:XX:XX:XX:XX:XX -t random -I 
     [XX:XX:XX:XX:XX:XX][LE]> connect 
     Attempting to connect to XX:XX:XX:XX:XX:XX 
     Error: connect error: Connection refused (111) 

谢谢您的帮助

编辑为康斯坦丁Chabirand的回答

$ systemctl status bluetooth 
    ● bluetooth.service - Bluetooth service 
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled) 
     Active: active (running) since Tue 2017-01-17 21:17:07 UTC; 1min 51s ago 
     Docs: man:bluetoothd(8) 
    Main PID: 587 (bluetoothd) 
     Status: "Running" 
     CGroup: /system.slice/bluetooth.service 
       └─587 /usr/libexec/bluetooth/bluetoothd --experimental 


$ bluetoothctl 
    [NEW] Controller B8:27:EB:FD:93:2B raspberrypi [default] 
    [bluetooth]# scan on 
    Discovery started 
    .... 

    [bluetooth]# scan off 
    [bluetooth]# connect XX:XX:XX:XX:XX:XX 
    Attempting to connect to XX:XX:XX:XX:XX:XX 
    Failed to connect: org.bluez.Error.Failed 

编辑2

与简单的解决方案重新安装后:

$ bluetoothctl -v 
    5.43 

$ systemctl status bluetooth 
    ● bluetooth.service - Bluetooth service 
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled) 
     Active: active (running) since Wed 2017-01-18 15:46:53 UTC; 3min 37s ago 
     Docs: man:bluetoothd(8) 
    Main PID: 586 (bluetoothd) 
     Status: "Running" 
     CGroup: /system.slice/bluetooth.service 
       └─586 /usr/local/libexec/bluetooth/bluetoothd --experimental 

$ sudo bluetoothctl 
    [bluetooth]# connect XX:XX:XX:XX:XX:XX 
    Attempting to connect to XX:XX:XX:XX:XX:XX 
    Failed to connect: org.bluez.Error.Failed 
+0

那么在这一点上或者你的BLE设备不允许连接,或者bluez不能在你的rpi上工作。 您是否尝试使用bluetoothctl连接到其他设备?它有用吗? “info XX:XX:XX:XX:XX”是否会返回有关您设备的正确信息? –

+0

我尝试过使用其他设备,并且连接每次都失败。和“信息XX:XX:XX:XX:XX”给我正确的信息(至少没有什么奇怪的我)。我也尝试了其他rpi,结果如下:s –

回答

3

感谢Constantin Chabirand,我做到了。我需要更多的命令行才能使其工作,并且我需要更改BLE设备的广告频率(我仍然需要对此进行一些测试)。

这里是我曾经在我的rpi3安装的bluez并连接到BLE装置的精确命令:

sudo apt-get update 
sudo apt-get upgrade 
sudo apt-get dist-upgrade 
sudo apt-get install -y libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev 

wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.43.tar.xz 
tar xf bluez-5.43.tar.xz 
cd bluez-5.43/ 

./configure 
make 
sudo make install 
sudo reboot 

# check version 
bluetoothctl -v 

sudo nano /lib/systemd/system/bluetooth.service 
     # Add --experimental to this lane 
     ExecStart=/usr/local/libexec/bluetooth/bluetoothd --experimental 

sudo systemctl daemon-reload 
sudo systemctl restart bluetooth 
sudo hciconfig hci0 up 
sudo reboot 

sudo usermod -G bluetooth -a pi 
sudo reboot 

就是这样。再次感谢你的帮助。

1

bash命令的结果是什么systemctl status bluetooth

你可以开始bluetoothctl(只需在你的shell中输入)?

我也使用树莓派3连接到BLE设备,我不需要补丁。开始一个新的与bluez5.43安装和后期两个命令的结果我已经写了


UPDATE

对于安装我做到了,我可以在最简单的方法。我跟着“编译这个包是最简单的方法:”在INSTALL文件,这是部分:

wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.43.tar.xz 

tar xf bluez-5.43.tar.xz 

cd bluez-5.43.tar.xz 

./configure 

make 

make install 

你成功地连接到使用别的东西你BLE装置?像智能手机?有些应用程序可以读取gatt atrributes。

更新2

我没有删除的事情。仅仅在其余的顶部安装bluez5.43。当我运行 bluetoothctl -v它返回:5.43。

当我运行容易名单--installed是可以看到自动安装以下软件包:

bluez/stable,now 5.23-2+rpi2 armhf [installed,automatic] 
bluez-firmware/stable,now 1.2-3+rpi1 all [installed,automatic] 
bluez-obexd/stable,now 5.23-2+rpi2 armhf [installed,automatic] 
bluez-tools/stable,now 0.2.0~20140808-3 armhf [installed] 

正如你可以看到我仍然安装了旧版本。

+0

谢谢你的回答。我添加了你要求的结果。每个想法似乎都运作良好,但没有联系。我会尝试没有补丁的其他安装。你有解释你所做的安装的链接吗? –

+0

在安装新版本之前是否卸载了bluez? –

+0

是的,我有几个连接在一起的设备和应用程序。我正在尝试你的简单解决方案。 –

1

我需要安装bluez-5.43以避免在脚本中使用bluetoothctl时缺省的缺省bluez-5.23中的错误。

您可以从拉伸安装二进制版本,但我的经验是,您经常遇到其他依赖项。

我在Ubuntu-16.04下有同样的问题,并使用Ubuntu-Zesty的deb-src包来解决这个问题。由于这只是我在Raspberry pi上使用过的debian软件包,在使用USB-蓝牙适配器时工作得很好。为了使RPI-3在通过串行线连接蓝牙控制器的情况下工作,您还需要安装../issue/30补丁。

这样做的好处是,一旦你的Raspbian将包含一个更新的bluez版本,它将取代我们在这里做的,如果你有更多的raspbian系统,你当然只需要安装生成的.deb包

这是我做过什么(免提):

#!/bin/bash 
sudo apt-get install devscripts debhelper dh-autoreconf flex bison libdbus-glib-1-dev libglib2.0-dev libcap-ng-dev libudev-dev l 
ibreadline-dev libical-dev check dh-systemd libebook1.2-dev 

wget https://launchpad.net/ubuntu/+archive/primary/+files/bluez_5.43.orig.tar.xz 
wget https://launchpad.net/ubuntu/+archive/primary/+files/bluez_5.43-0ubuntu1.debian.tar.xz 
wget https://launchpad.net/ubuntu/+archive/primary/+files/bluez_5.43-0ubuntu1.dsc 

tar xf bluez_5.43.orig.tar.xz 
cd bluez-5.43 
tar xf ../bluez_5.43-0ubuntu1.debian.tar.xz 
# install patches relevant for rpi-3 bluetooth 
. /etc/os-release 
if [ $ID = raspbian ]; then 
    wget https://gist.github.com/pelwell/c8230c48ea24698527cd/archive/3b07a1eb296862da889609a84f8e10b299b7442d.zip 
    cd debian/patches 
    unzip ../../3b07a1eb296862da889609a84f8e10b299b7442d.zip 
    for i in c8230c48ea24698527cd-3b07a1eb296862da889609a84f8e10b299b7442d/*;do 
     mv $i . 
     basename $i >> series 
    done 
    rmdir c8230c48ea24698527cd-3b07a1eb296862da889609a84f8e10b299b7442d 
    cd ../.. 
fi 
# end of Raspian related patches 
debchange --local=~lorenzen 'Backport to Xenial' 
debuild -b -j4 
cd .. 
sudo dpkg -i *.deb 

这应该在其他的Debian衍生系统工作过, https://askubuntu.com/a/884062/655086

0

我面临同样的问题是c使用Raspberry Pi 3内置蓝牙连接和播放BLE设备。首先,我学会了如何通过下面的网页播放和控制一个工具bluetoothctl

[https://mcuoneclipse.com/2016/12/19/tutorial-ble-pairing-the-raspberry-pi-3-model-b-with-hexiwear/][1]

在本教程中,你BLE设备成功连接后,你可以用你要玩的属性工作。例如,如果要使用蓝牙UART TX或RX的属性,则只需输入以下命令,然后读取或写入该特性的该属性值即可。

list-attributes 00:34:40:0A:00:4E 
select-attribute /org/bluez/hci0/dev_00_32_40_08_00_12/service0026/char0027 
read 
write 

如果有任何人谁是充分认识创建树莓派3之间连接蓝牙内置BLE Arduino的用竹叶提取,请分享你的知识。 ;)