nrjps
Posts: 11
Joined: Wed May 31, 2017 12:58 pm

Bluetooth LE upgrade not working

Mon Jul 03, 2017 1:46 pm

The default version of bluez in Raspbian-Jesse is 5.23, which allows bluetooth low energy (BLE) devices to pair and even connect but does not respond to them thereafter! To solve this, one has to install an updated version of bluez. Earlier, I successfully followed this link: https://learn.adafruit.com/install-blue ... stallation, which gives the steps to upgrade to bluez-5.37. Bluetooth devices worked after enabling the experimental flag, restarting the bluetooth adapter, *and a reboot*.

When I tried doing the same thing on another installation of Raspbian now, the system behaves as if it has the old bluez version running. Indeed, I get the perplexing results given below

Code: Select all

    bluetoothd --version
    5.23
    bluetoothctl --version
    5.37
Is this normal? It looks like inspite of the upgrade, the old bluez version is being *actually* used -- but I don't know, I'm guessing. How do I remedy this? If you are suggesting removing bluez-5.23, please tell me how to do that. I tried uninstalling bluez from pi, but that removes pi-bluetooth as well. What should I remove and what should I keep, for the BLE devices to work? And how?

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth LE upgrade not working

Mon Jul 03, 2017 2:43 pm

I have not tried upgrading BlueZ 5.23, as I have never experienced problems, including connecting to BLE devices. I'd be interested in information about the problems you are having.

Bluetoothd and bluetoothctl are separate programs, so there's nothing perplexing about running different versions of each.

I would look at the bluetoothd systemd service unit, which should be at /etc/systemd/system/dbus-org.bluez.service. Make sure it's invoking the bluetoothd you want. Failing that I would look at one (or all) of the several threads on this forum regarding upgrading BlueZ.

ericcooper
Posts: 118
Joined: Sat Apr 08, 2017 6:23 pm

Re: Bluetooth LE upgrade not working

Mon Jul 03, 2017 3:55 pm

Following the Adafruit instructions probably resulted in bluetooth software being installed in /usr/local/bin, /usr/local/sbin, etc. The system-provided versions are in /usr/bin, /usr/sbin, etc. Try doing "which bluetoothd" and "which bluetoothctl" to see if there's a conflict, and remove the ones in /usr/local if necessary.

nrjps
Posts: 11
Joined: Wed May 31, 2017 12:58 pm

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 4:19 am

Douglas6 wrote:I would look at the bluetoothd systemd service unit, which should be at /etc/systemd/system/dbus-org.bluez.service. Make sure it's invoking the bluetoothd you want.
For running BLE devices, I had put the experimental flag in /lib/systemd/system/bluetooth.service as per the adaruit tutorial. Now when I see the file you recommended, /etc/systems/system/dbus-org.bluez.service I see the same content in both:

Code: Select all

[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)
ConditionPathIsDirectory=/sys/class/bluetooth

[Service]
Type=dbus
BusName=org.bluez
ExecStart=/usr/local/libexec/bluetooth/bluetoothd --experimental
NotifyAccess=main
#WatchdogSec=10
#Restart=on-failure
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
LimitNPROC=1

[Install]
WantedBy=bluetooth.target
Alias=dbus-org.bluez.service
Can you tell me how to tell the system to use a different version of bluez, in my case 5.37? I think the problem is just that -- telling the system which one to use. Something like what @erlcooper is saying.

nrjps
Posts: 11
Joined: Wed May 31, 2017 12:58 pm

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 4:29 am

ericcooper wrote:Following the Adafruit instructions probably resulted in bluetooth software being installed in /usr/local/bin, /usr/local/sbin, etc. The system-provided versions are in /usr/bin, /usr/sbin, etc. Try doing "which bluetoothd" and "which bluetoothctl" to see if there's a conflict, and remove the ones in /usr/local if necessary.
Looks like what you are saying has happened. So here are the results of your suggestions:

Code: Select all

which bluetoothd
/usr/sbin/bluetoothd
which bluetoothctl
/usr/local/bin/bluetoothctl
I don´t understand what you mean by ¨see if there´s a conflict¨; it looks like my system is defaulting to the old version without any conflict. However, if I install blueman, there is some issue with two controller software trying to tell the system what to do.

Anyway, you are recommending that I remove the one in /usr/local/bin, but that is the new version that I installed, 5.37 (blutetoothctl --version), whereas the old one in usr/sbin/ is 5.23 (bluetoothd --version). I want to delete the old one. It will be great if you or Douglas can tell me how to safely delete the old version.

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 5:06 am

Again, don't confuse bluetoothd with bluetoothctl. Two very different programs. You're running the new bluetoothctl, so forget about that one. It's fine.

It sounds like you have two services trying to start bluetoothd (dbus-org.bluez.service and bluetooth.service). Look at them again, specifically the 'ExecStart=' lines. I expect they will have different paths for bluetoothd. Try:

Code: Select all

systemctl status dbus-org.bluez
and

Code: Select all

systemctl status bluetooth 
I'm guessing the first is successful and the second is not. You want to disable the first, so do:

Code: Select all

sudo systemctl disable dbus-org.bluez
Reboot, and check the statuses again.

I wouldn't worry about deleting the old version, just don't try to start it.

nrjps
Posts: 11
Joined: Wed May 31, 2017 12:58 pm

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 2:04 pm

Both the outputs are same:

Code: Select all

[email protected]:~ $ systemctl status dbus-org.bluez
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)
   Active: active (running) since Mon 2017-07-03 20:04:30 IST; 1min 10s ago
     Docs: man:bluetoothd(8)
 Main PID: 726 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─726 /usr/local/libexec/bluetooth/bluetoothd --experimental

Code: Select all

[email protected]:~ $ systemctl status bluetooth
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)
   Active: active (running) since Mon 2017-07-03 20:04:30 IST; 1min 19s ago
     Docs: man:bluetoothd(8)
 Main PID: 726 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─726 /usr/local/libexec/bluetooth/bluetoothd --experimental
In this situation, I expect my bluetooth to not work if I disable dbus-org.bluez, but I will try nontheless and post later.

nrjps
Posts: 11
Joined: Wed May 31, 2017 12:58 pm

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 2:11 pm

@Douglas6: Both outputs are the same -- even after disabling dbus-org.bluez. And same as earlier...

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 2:15 pm

Interesting. Both statuses refer to /etc/systemd/system/bluetooth.service. What do the 'ExecStart=' lines say in each .service file? What do you get with

Code: Select all

/usr/local/libexec/bluetooth/bluetoothd  --version 
Don't forget to reboot between tests.

nrjps
Posts: 11
Joined: Wed May 31, 2017 12:58 pm

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 2:21 pm

Strange, /usr/local/libexec/bluetooth/bluetoothd --version gives 5.37! :o

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 2:26 pm

OK. You might well be running 5.37 then. What about

Code: Select all

ps aux | grep bluetooth

DirkS
Posts: 9758
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 2:27 pm

Douglas6 wrote:Interesting. Both statuses refer to /etc/systemd/system/bluetooth.service. What do the 'ExecStart=' lines say in each .service file?
I see the same on my system (with v5.23. The system file shows it as an alias:

Code: Select all

[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)

[Service]
Type=dbus
BusName=org.bluez
ExecStart=/usr/lib/bluetooth/bluetoothd
NotifyAccess=main
#WatchdogSec=10
#Restart=on-failure
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
LimitNPROC=1

[Install]
WantedBy=bluetooth.target
Alias=dbus-org.bluez.service

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 2:29 pm

Ah, thank you, DirkS. That would explain that (sort of).
Last edited by Douglas6 on Tue Jul 04, 2017 2:34 pm, edited 1 time in total.

nrjps
Posts: 11
Joined: Wed May 31, 2017 12:58 pm

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 2:33 pm

Code: Select all

[email protected]:/usr/local/libexec/bluetooth $ ps aux | grep bluetooth
root       720  0.0  0.3   5008  3388 ?        Ss   20:26   0:00 /usr/local/libexec/bluetooth/bluetoothd --experimental
pi        1978  0.0  0.2   4280  2012 pts/0    S+   20:40   0:00 grep --color=auto bluetooth

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 2:35 pm

Yup. Looks like you are good to go.

nrjps
Posts: 11
Joined: Wed May 31, 2017 12:58 pm

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 2:45 pm

But my problem is still unresolved. Earlier, with bluez-5.37 and the --experimental flag set, I could connect my mouse successfully and the pointer would respond. Now, though my mouse connects with the device, the pointer doesn't respond -- in fact nothing happens. I don't understand at which level in the system the problem exists -- what else I need to do to connect my mouse. I tried installing blueman, to no avail.

Thanks for your help in confirming that I have bluez-5.37, and do post if you have any other suggestions to get my Logitech MX Anywhere 2 mouse connected to the Pi. What annoys me is that I did it once earlier and now I cannot redo it! :)

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 3:02 pm

You might try one of the tips posted here: https://askubuntu.com/questions/741330/ ... art/769095. It's an Ubuntu forum, but still.

You might try installing BlueZ 5.43 (that's the version in Debian Stretch, so should be stable).

Apart from that, I'm in over my head, never having used a BLE mouse. You could, it appears, use that mouse with a Logitech unified receiver dongle.

nrjps
Posts: 11
Joined: Wed May 31, 2017 12:58 pm

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 7:57 pm

I had switched off the Pi after my previous comment. Now, I switched it on again to follow the steps on the askubuntu, and just for fun, decided to switch my bluetooth mouse to Pi -- and it worked! Douglas6, I swear that I had done sudo reboot wherever you asked me to -- I swear I followed the instructions correctly. I had done sudo reboot countless other times. The only difference now was that I did sudo halt, and the Pi was disconnected from the power bank that I use to power it.

I want to mention something for the benefit of others. I had installed blueman in my desperate attempts to get the bluetooth working, so I suspected that caused it to work. To check, I uninstalled blueman first, shut down the Pi, disconnected it from power bank, switched on, and my bluetooth mouse worked still. Then I removed the dependencies of blueman -- suspecting may be one of the dependencies was important in some way -- shut down the Pi, disconnected it, switched on, and the bluetooth mouse still works. Therefore, either shutting down the Pi completely instead of rebooting it was the key, or something that Douglas6 suggested along the way worked.

Thanks to all who tried to help. And Douglas6, from reading other posts about bluetooth on Pi, I know that you generally go an extra mile to solve problems -- thanks a lot! :D

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 8:10 pm

Very glad to hear it's working. Part of the tip on that link I sent was to power down and up the Bluetooth adapter, so perhaps power cycling the Pi was part of the solution.

Folks occasionally ask here about BLE mice, and now maybe I can better help them. Thanks for working through it.

nrjps
Posts: 11
Joined: Wed May 31, 2017 12:58 pm

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 8:22 pm

I tried with another installation of Pi (same Raspbian-Jesse, but) where I had bluez-5.45 (the latest as of now, and which does not need the --experimental flag) installed and where was facing the same problem!

This time, to connect the mouse I followed the steps given in the askubuntu link, and the mouse did not work inspite of powering off the bluetooth adapter and switching it on again -- what worked is shutting down the Pi and switching on again. May be a reboot suffices for others, but I have my Pi piggy-backing on a 10inch LCD screen (with its own drivers), and I notice that ubfan1 has commented about some other software interfering, so may be that is what necessitates shutting down the system(?)

Moreover, I had not installed blueman in this installation, so can confirm that nothing extra is needed to connect BLE devices to RPi3, except for upgrading bluez and shutting down your Pi after adding the BT mouse device -- especially if it connects successfully but does not respond to movement. Hope this helps someone.

nrjps
Posts: 11
Joined: Wed May 31, 2017 12:58 pm

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 8:31 pm

In fact, on this second Pi installation with bluez-5.45, I didn't even have to disable one of the bluetooth installations...

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 8:36 pm

Well, that's another interesting data point, thanks.

And for others reading this: I don't believe installing blueman is ever a good idea on a recent Raspbian. A Bluetooth GUI is already included, and blueman can conflict in various ways.

User avatar
Douglas6
Posts: 4558
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth LE upgrade not working

Tue Jul 04, 2017 8:43 pm

nrjps wrote:In fact, on this second Pi installation with bluez-5.45, I didn't even have to disable one of the bluetooth installations...
So what you are saying is that I was really no help at all :). Sorry for the garden path.

MikeZA
Posts: 1
Joined: Wed Feb 27, 2019 6:44 am

Re: Bluetooth LE upgrade not working

Wed Feb 27, 2019 7:43 am

Hi All

Thank you soooo much for taking time to read and reply on my problem.

I have been reading many threads trying to uncover the cause of my problem. I am using the tinyb java library from Intel get two pi's (3b+ and a zero w) to communicate via BLE.

Using "sudo hcitool lescan" from each pi, I am able to detect the other pi (and 10 other devices in the apartment block). However, when using below code from 3b+ (360 loops with 10sec sleeps in between), i find up to 23 other apartment block devices but not the pi zero w. When comparing the two device lists I noticed that only 1 device (from somewhere in apartment block) is common to both listings. So it seems that tinyb is picking up a ble device, just not my pi zero w.

Furthermore, I am running bluez v5.43. i tried to upgrade to v5.48 and v5.50. Everything seems to work fine during the make process until i run "make -j4". Whilst executing the command, the pi3b+ reboots. See error 1 below. From then the install does not want to continue. See error 2 below.

//----------------error 1 tag

[email protected]:~/Documents/Apps/OS/bluez-5.50 $ make -j4
GEN lib/bluetooth/hci.h
GEN lib/bluetooth/hci_lib.h
GEN lib/bluetooth/bluetooth.h
GEN lib/bluetooth/sco.h
GEN lib/bluetooth/sdp.h
GEN lib/bluetooth/l2cap.h
GEN lib/bluetooth/sdp_lib.h
GEN lib/bluetooth/rfcomm.h
GEN lib/bluetooth/cmtp.h
GEN src/builtin.h
GEN lib/bluetooth/bnep.h
GEN lib/bluetooth/hidp.h
GEN obexd/src/builtin.h
make --no-print-directory all-am
GEN src/bluetooth.service

(reboots or terminates ssh session, depending if ssh used or direct connection to pi via monitor and keyboard)

//-----------error2 tag
[email protected]:~/Documents/Apps/OS/bluez-5.50 $ sudo make install
make: *** No rule to make target 'install'. Stop.
[email protected]:~/Documents/Apps/OS/bluez-5.50 $ ^C
[email protected]:~/Documents/Apps/OS/bluez-5.50 $ make -j4
make: *** No targets. Stop.

I am not sure if upgrading from bluez 5.43 will help with detecting my pi zero from 3b+ using tinyb. This is the primary problem i need to solve. Getting to the root of the upgrading problem will be a bonus though if it does not impact the tinyb library function, else it is a necessity.

Tx
Mike


//=================CODE======================//

static BluetoothDevice getDevice(String address, BluetoothManager manager) throws InterruptedException
{
BluetoothDevice sensor = null;

for (int i = 0; (i < 360) && running; ++i)
{
List<BluetoothDevice> list = manager.getDevices();

for (BluetoothDevice device : list)
{
if (device.getAddress().equals(address))
{
sensor = device;
System.out.println("MATCH : Target - " + address +" - Found - " + device.getAddress() + "!!!!!!!!");
}
else
{
System.out.println("Not match : Target - " + address +" - Found - " + device.getAddress() );
}
}

if (sensor != null)
{
return sensor;
}
Thread.sleep(10000);
}
return null;
}

Return to “General discussion”