2016-12-27 143 views
4

我正在運行我的家庭計算機運行Ubuntu和Python 2.7的測試,希望讓Raspberry Pi 3使用具有自定義服務和特性的BLE進行廣告。我已經在兩個設備以及dbus-python上安裝了藍牙版本5.42(使用推薦的方法)。我的電腦和Raspberry Pi都可以使用hci0 lescan 0命令做廣告,但我想用bluez示例腳本做廣告,example-gatt-client.py和example-advertisement.py找到here,因爲我想用我的自己的習慣特徵。LEAdvertisingManager1從DBus.ObjectManager.GetManagedObjects丟失

家用電腦 - 內核版本4.4.0-31通用

我可以創建自定義特性和運行example-gatt-server.py做廣告,沒有問題的example-advertise.py我的家用電腦。我遇到的一個問題是我需要啓用Bluez實驗模式,將--experimental添加到位於/lib/systemd/system/bluetooth.service的bluetooth.service文件。安裝dbus-python庫也有點麻煩,因爲我必須自己爲Python2構建和安裝它。

advertise.py腳本查找名爲「org.bluez.LEAdvertisingManager1」的特定廣告界面。 gatt-server.py腳本查找「org.bluez.GattManager1」。我可以檢查是否通過運行以下命令存在接口:

dbus-send --system --dest=org.bluez --print-reply/org.freedesktop.DBus.ObjectManager.GetManagedObjects 

這些接口被發現和我家裏的電腦上正常工作。腳本運行沒有問題。

樹莓派 - 內核版本38年4月4日至V7 +

在相同的bluez版本並啓用了實驗性的功能,我試圖運行advertise.py當遇到這樣的錯誤:

LEAdvertisingManager1界面未找到。

而當我執行命令「systemctl status bluetooth」時,它顯示啓用了實驗標誌,但運行時沒有看到LEAdvertistingManager1。

dbus-send --system --dest=org.bluez --print-reply/org.freedesktop.DBus.ObjectManager.GetManagedObjects 

我可以跑不過沒有問題的gatt-server.py腳本,這意味着「org.bluez.GattManager1」被發現,工作正常。我在這裏錯過了什麼?

我已經搜索過這個問題,但唯一的建議是啓用實驗功能,並確保我的內核是> = 4.1。

回答

8

我解決了我的問題!經過很多調試並查看bluez錯誤日誌,我意識到我沒有在我的Pi上正確安裝bluez。以下是從新安裝的raspbian中正確安裝bluez的步驟。

sudo apt-get update 
sudo apt-get upgrade 
mkdir bluez 
cd bluez 
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.43.tar.xz 
tar xvf bluez-5.43.tar.xz 
cd bluez-5.43/ 
sudo apt-get install -y libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev 
./configure 
sudo make 
sudo make install 

然後,啓用實驗模式。 Bluez v5.23可能不需要這個功能,但我仍然使用它。

cd 
sudo nano /lib/systemd/system/bluetooth.service 

添加--experimental行 「ExecStart =在/ usr /本地/ libexec目錄/藍牙/ bluetoothd」 後 所以它應該看起來像

ExecStart=/usr/local/libexec/bluetooth/bluetoothd --experimental 

然後讓藍牙與這個新配置下運行

sudo systemctl daemon-reload 
sudo systemctl restart bluetooth 

如果你想運行一個測試廣告你可以使用以下命令:

sudo hciconfig hci0 up 
sudo hciconfig hcio leadv 0 

您的Pi3應宣傳爲「raspberrypi」,如果您嘗試使用您最喜愛的BLE應用程序(我在iOS上使用LiteBlue)連接到它,它應該有一些默認特性。

爲了檢查是否「LEAdvertisingManager1」存在,我們需要運行

dbus-send --system --dest=org.bluez --print-reply/org.freedesktop.DBus.ObjectManager.GetManagedObjects 

最後,不要嘗試從鏈接中的腳本在原來的職位。他們非常過時。相反,運行位於您所做的目錄中的示例腳本。

cd bluez/bluez-5.43/tests 

運行之前,你需要通過以下步驟來安裝的dbus-python的:

sudo apt-get install python-dev libdbus-1-dev libdbus-glib-1-dev 
sudo apt-get install python-pip 
sudo apt-get install --reinstall python-gi 
sudo python2.7 -m pip install dbus-python 

如果你想運行使用python2.7(這是我做的)例子,廣告腳本,你必須更改線路例如,從做廣告

import gobject 

from gi.repository import GObject as gobject 

如果你想添加自己的自定義特性,你需要同時運行應該無需修改即可運行例如總協定的服務器。

我也有一個小問題,即我的iPhone被卡住詢問PI3並且將無法連接。這是通過簡單地重置藍牙來解決的。

sudo systemctl daemon-reload 
sudo systemctl restart bluetooth 

祝你好運!

+0

感謝您的詳細說明。然而在Raspi 3,我得到:'須藤hciconfig hci0 up' - >'無法獲取設備信息:沒有這樣的device'。我們是否應該在https://github.com/ukBaz/python-bluezero/issues/30中描述的運行'make'之前應用補丁? –

+0

現在這對我有用:我應用了hciattach-patch(不知道是否有必要),並且還運行'sudo/usr/bin/hciattach/dev/ttyAMA0 bcm43xx 921600 noflow -')。重啓之間可能是必要的。'sudo hcitool lescan'發現外圍設備。 –

+0

爲我完美工作。重大進展。謝謝 – user462990

1

雖然這是越來越Bluetoothctl以配合bluez的最新版本,Bluetoothd保持在5.23這是舊版本。問題似乎是,當你安裝PI-藍牙將其安裝5.23作爲依賴。如何獲得最新版本的Blueoothd?我注意到顯然是從上面的步驟安裝。重新啓動後仍然在5.23。

PI @樹莓派:〜/ bluez的-5.37 $ bluetoothd -v 5.23 PI @樹莓派:〜/ bluez的-5.37 $ bluetoothctl -v 5.37

+0

你試過完整的路徑嗎? make文件在我運行時並沒有替換原來的可執行文件,而是將它放在不同的文件夾中。你可以試試'/ usr/local/libexec/bluetooth/bluetoothd --version'。 – cloisteredmonkey