A bit late here, but I recently suffered the headache of following a variety of different guides, none of which worked for me. So here is another guide...that probably won't work for you ;)
I downloaded the most recent version from the official page: bluez.org/download. If that page is dead, use this one instead.
For example, at the time of writing it was 5.47, so I used (on my raspberry):
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.47.tar.xz
Then I extracted it and built it:
tar -xf bluez-5.47.tar.xz
cd bluez-5.47
Read the README
! It lists the dependencies and the configure switches:
Install the dependencies first: (glib, dbus, libdbus, udev, etc.) Most of them are already installed and if not they should be easy to install, all provided by package manager. Once you've done that:
./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var
I also added --enable-experimental
because I believe the GattCharacteristics object is part of the experimental features. Then do:
make
sudo make install
It takes maybe 10 minutes to compile. After installing, you should find
bluetoothd
in /usr/libexec/bluetooth
. You should also see bluetoothd in /usr/lib/bluetooth
.
Go to each of these directories and type
./bluetoothd --version
You'll note that the one in libexec is new and the one in lib is old.
BlueZ creates these d-bus objects and interface to expose the bluetooth devices to you in nice ways.
In order to make sure that d-bus is talking to you new BlueZ 5.47 and not your old BlueZ 5.23, you need to tell systemd
to use the new bluetooth daemon:
sudo vim /lib/systemd/system/bluetooth.service
Make sure the exec.start
line points to your new daemon in /usr/libexec/bluetooth
.
For me, that wasn't enough. No matter what, upon restart I always got bluetoothd 5.23... So I just created a symlink from the old one to the new.
First rename the old file:
sudo mv /usr/lib/bluetooth/bluetoothd /usr/lib/bluetooth/bluetoothd-543.orig
Create the symlink:
ln -s /usr/libexec/bluetooth/bluetoothd /usr/lib/bluetooth/bluetoothd
sudo systemctl daemon-reload
That should do it.
Now, I have to say this, even though it's not relevant to the question:
If you want to develop an application for your pi, read the blueZ docs folder. It introduces you to something called d-bus, which is really worth learning about, and allows you to develop your application in python, node.js, or c (and more). Watch this video on bluez dev.
There are a lot of red herrings out there: wrappers that attempt to give you "easy" functionality. Even resources that say there is a lack of documentation on how to develop bluetooth. However, as soon as you want to do anything beyond simply connecting to the device and viewing it's characteristics, you're going to realize the wrapper will fail you.
Do yourself a favor. Take a few hours to learn how BlueZ
works (the video I linked is solid gold). It uses something called d-bus. Read a bit about d-bus. If you like Python, look at the code in the test folder. Read the python dbus tutorial once or twice. It will pay off so nicely. I wasted a few days trying to find something easy, but this turned out to be the best way.
Good luck!