2017-01-17 234 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的用竹葉提取,請分享你的知識。 ;)