How to connect Raspberry PI to Android without cutting the sound? - bluetooth

I am working on a project using a Raspberry PI4 under Bullseye 64 bits and an Android smartphone. There is no Wi-Fi nor internet available.
I would like to inform Android the Raspberry has just started.
In the past I did something similar: when I turn may car on, I get a callback on my phone. To do that, on boot, I register a broadcast for android.bluetooth.device.action.ACL_CONNECTED. It works fine, because as soon as I turn the car on, the Bluetooth of the car connects to the phone.
Now in my current project the car role is played by the raspberry PI. I have connected the smartphone to the Raspberry PI using the standard Android UI. It works fine.
Later, from the Raspberry PI I run bluetoothctl connect MAC where MAC is the mac address of my smartphone. It works well, the devices are connected, and I get the callback in Android.
The problem comes from the fact the smartphone sees the Raspberry like headset, so I cannot hear the sounds played on my smartphone : there are send to Raspberry.
I spends days trying to fix that issue, but I did not found any solution. For example, if I tried to modify the bluetoothd daemon on the PI like this:
ExecStart=/usr/libexec/bluetooth/bluetoothd --noplugin=*
It is not working : I cannot connect the PI from the smartphone. I guess it is due to the profiles implemented in Android: If I remove everything from Bluetooth daemon Android does not found anything suitable.
Have you any idea how I could solve the issue?
Notice I could disconnect few seconds after connection as all I need is the information the Raspberry has started but I am not happy with that solution, the user may notice the interruption.
Thank you.

This might work. It may have been depracated or sidelined by dBus, so no promises. Try deleting the Pi's audio service with sdptool.
First list the services:
sudo sdptool records local
Find the service that looks like an audio link and note its handle which will be listed like this:
Service RecHandle: 0x10002
Then delete the service
sudo sdptool del 10002

I tried your suggestions, but I did not succeed.
Firstly I tried the usual process
Connect the smartphone to the PI from the standard Android UX.
On the PI, in bluetoothctl
I see this :
[NEW] Device yy:yy:yy:yy:yy:yy MyPhoneName
Request confirmation
[agent] Confirm passkey 798942 (yes/no): yes
[CHG] Device yy:yy:yy:yy:yy:yy Modalias: usb:v0FCEp020Dd0010
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001105-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001115-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001116-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 10000057-5749-5448-0037-000000000000
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: a82efa21-ae5c-3dde-9bbc-f16da7b16c5a
[CHG] Device yy:yy:yy:yy:yy:yy ServicesResolved: yes
[CHG] Device yy:yy:yy:yy:yy:yy Paired: yes
[CHG] Device yy:yy:yy:yy:yy:yy ServicesResolved: no
[CHG] Device yy:yy:yy:yy:yy:yy Connected: no
Android tried several times the connections.
I tried again from Android I see this :
[CHG] Device 3C:01:EF:6F:A8:BF Connected: yes
Authorize service
[agent] Authorize service 00001108-0000-1000-8000-00805f9b34fb (yes/no): yes
Next step : forget the PI from the phone and remove the phone from the PI
bluetoothctl remove yy:yy:yy:yy:yy:yy
Secondly remove the records using sdptool
Now removing the 2 records: (I did that after adding ‘—compat’ to bluetoothd in order to make sdptool working):
$ sudo sdptool browse local
Browsing FF:FF:FF:00:00:00 ...
Service RecHandle: 0x10000
Service Class ID List:
"PnP Information" (0x1200)
Profile Descriptor List:
"PnP Information" (0x1200)
Version: 0x0103
Browsing FF:FF:FF:00:00:00 ...
Service Search failed: Invalid argument
Service Name: Generic Access Profile
Service Provider: BlueZ
Service RecHandle: 0x10001
Service Class ID List:
"Generic Access" (0x1800)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM: 31
"ATT" (0x0007)
uint16: 0x0001
uint16: 0x0005
Service Name: Generic Attribute Profile
Service Provider: BlueZ
Service RecHandle: 0x10002
Service Class ID List:
"Generic Attribute" (0x1801)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM: 31
"ATT" (0x0007)
uint16: 0x0006
uint16: 0x000f
Service Name: Device Information
Service Provider: BlueZ
Service RecHandle: 0x10003
Service Class ID List:
"" (0x180a)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM: 31
"ATT" (0x0007)
uint16: 0x0010
uint16: 0x0012
Service Name: **Headset Voice gateway**
Service RecHandle: 0x10004
Service Class ID List:
"Headset Audio Gateway" (0x1112)
"Generic Audio" (0x1203)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 12
Profile Descriptor List:
"Headset" (0x1108)
Version: 0x0102
Service Name: **Headset unit**
Service RecHandle: 0x10005
Service Class ID List:
"Headset" (0x1108)
"" (0x1131)
"Generic Audio" (0x1203)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 3
Profile Descriptor List:
"Headset" (0x1108)
Version: 0x0102
So I removed the to last services :
$ sudo sdptool del 0x10004
Service Record deleted.
$ sudo sdptool del 0x10005
Service Record deleted.
If again I run sudo sdptool browse local, there are gone.
But If I run
bluetootctl show
I do not see any changes :
[bluetooth]# show
Controller xx:xx:xx:xx:xx:xx (public)
Name: mypi
Alias: mypi
Class: 0x00200000
Powered: yes
Discoverable: yes
DiscoverableTimeout: 0x00000000
Pairable: yes
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Headset (00001108-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb)
UUID: Device Information (0000180a-0000-1000-8000-00805f9b34fb)
Modalias: usb:v1D6Bp0246d0537
Discovering: no
Roles: central
Roles: peripheral
Advertising Features:
ActiveInstances: 0x00 (0)
SupportedInstances: 0x05 (5)
SupportedIncludes: tx-power
SupportedIncludes: appearance
SupportedIncludes: local-name
Again, paring from the smartphone :
[NEW] Device yy:yy:yy:yy:yy:yy MyPhoneName
Request confirmation
[agent] Confirm passkey 887536 (yes/no): yes
[CHG] Device yy:yy:yy:yy:yy:yy Modalias: usb:v0FCEp020Dd0010
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001105-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001115-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001116-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: 10000057-5749-5448-0037-000000000000
[CHG] Device yy:yy:yy:yy:yy:yy UUIDs: a82efa21-ae5c-3dde-9bbc-f16da7b16c5a
[CHG] Device yy:yy:yy:yy:yy:yy ServicesResolved: yes
[CHG] Device yy:yy:yy:yy:yy:yy Paired: yes
[CHG] Device yy:yy:yy:yy:yy:yy ServicesResolved: no
[CHG] Device yy:yy:yy:yy:yy:yy Connected: no
The connection is failing.
I guess Android to not get any suitable services, so it gave up.
I have noticed one thing: if I restart the bluetooth daemon (sudo systemctl restart bluetooth) the 2 records are back.
I am wondering if there is something in Raspberry PI OS which force these 2 services.
Conclusion
I am stuck.
I thought I had solved my problem because when I initiate the connection to phone from the PI (after the pairing from the phone), Android triggers an event ACTION_ACL_CONNECTED followed by a ACTION_ACL_DISCONNECTED which is enough for me.
Unfortunately, it only works for a while. If I wait too long, I can't get it to work.

Related

Bluetooth Vodafone TV remote not connecting to Linux /w bluez

Im running a mostly fresh install of Arch Linux(5.19.12) with bluez(5.65). The specific bluetooth device in question is the Vodafone TV Remote
bluetoothctl info
Device 8C:3A:7E:52:38:47 (public)
Name: VODAFONE REMOTE CONTROL
Alias: VODAFONE REMOTE CONTROL
Appearance: 0x0180
Paired: no
Bonded: no
Trusted: no
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Human Interface Device (00001812-0000-1000-8000-00805f9b34fb)
UUID: Battery Service (0000180f-0000-1000-8000-00805f9b34fb)
UUID: Device Information (0000180a-0000-1000-8000-00805f9b34fb)
ManufacturerData Key: 0x0093
ManufacturerData Value:
02 85 0f 00 57 41 4b 45 55 50 e0 00 ....WAKEUP..
...
The typical pair attempt goes like this. Although I have tried many variants without any success. Sometimes Im able to get it to connect my some magical chance, but are unable to replicate.
[bluetooth]# power on
Changing power on succeeded
[CHG] Controller 34:20:03:DF:2E:6A Powered: yes
[CHG] Device DF:6C:AD:D9:82:7A Connected: yes
[CHG] Device DF:6C:AD:D9:82:7A ServicesResolved: yes
[SmartTV Keyboard]# agent on
Agent registered
[SmartTV Keyboard]# scan on
Discovery started
[CHG] Controller 34:20:03:DF:2E:6A Discovering: yes
[NEW] Device 8C:3A:7E:52:38:47 VODAFONE REMOTE CONTROL
[SmartTV Keyboard]# pair 8C:3A:7E:52:38:47
Attempting to pair with 8C:3A:7E:52:38:47
[CHG] Device 8C:3A:7E:52:38:47 Connected: yes
[SmartTV Keyboard]# scan off
[CHG] Controller 34:20:03:DF:2E:6A Discovering: no
Discovery stopped
[CHG] Device 8C:3A:7E:52:38:47 ServicesResolved: yes
[CHG] Device 8C:3A:7E:52:38:47 ServicesResolved: no
[CHG] Device 8C:3A:7E:52:38:47 Connected: no
[CHG] Device 8C:3A:7E:52:38:47 Connected: yes
[CHG] Device 8C:3A:7E:52:38:47 ServicesResolved: yes
[CHG] Device 8C:3A:7E:52:38:47 ServicesResolved: no
[CHG] Device 8C:3A:7E:52:38:47 Connected: no
...
busctl log
btmon log
Fiddling with it, I got it to connect and pair. Although I still have the repeating service resolving issue. Heres the log. It also gives me this more populated info instead
Device 8C:3A:7E:52:38:47 (public)
Name: VODAFONE REMOTE CONTROL
Alias: VODAFONE REMOTE CONTROL
Appearance: 0x0180
Paired: yes
Bonded: yes
Trusted: yes
Blocked: no
Connected: yes
WakeAllowed: yes
LegacyPairing: no
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Immediate Alert (00001802-0000-1000-8000-00805f9b34fb)
UUID: Link Loss (00001803-0000-1000-8000-00805f9b34fb)
UUID: Tx Power (00001804-0000-1000-8000-00805f9b34fb)
UUID: Device Information (0000180a-0000-1000-8000-00805f9b34fb)
UUID: Battery Service (0000180f-0000-1000-8000-00805f9b34fb)
UUID: Human Interface Device (00001812-0000-1000-8000-00805f9b34fb)
UUID: Vendor specific (2141e100-213a-11e6-b67b-9e71128cae77)
Modalias: usb:v06E7p8073d0100
ManufacturerData Key: 0x0093
ManufacturerData Value:
Whenever I try to connect, the remote stops flashing its paring light, indicating that its paired. This happens as soon as bluetoothctl reports Device 8C:3A:7E:52:38:47 Connected: yes
How would I go about connecting to this device? Am I missing some module? Is there something missing from the kernel?

Bluetooth Pairing with SSP Passkey Entry with chosen Passkey does not work

For a project i need to connect two Raspberry Pis with Bluetooth SSP Passkey entry. For the sake of the project, the passkey should be chosen and entered in both devices. This should be handled by a script which changes the passkey periodically in a pseudo-random fashion( like Passkey = Hash(time+seed)).
Hardware:
2x Raspberry Pi 4 Model b Rev 1.2
Operating System: Raspbian GNU/Linux 10 (buster)
Kernel: Linux 5.4.79-v7l+
Architecture: arm
BlueZ Version 5.50
The Bluetooth Core Spec 5.0 states on page 1441
"when one device has numeric input only and the other device has either a display or numeric input capability
or when both devices only have numeric input capability. In this step, one
device display a number to be entered by the other device or the user enters a
number on both devices."
From my understanding, the passkey will be generated by the device with output capability if one device possesses an Output capability and the other device possesses an KeyboardOnly/DisyplayYes/No IOCapability. If both devices only possess the KeyboardOnly capability, then the passkey is chosen by the user and entered in both devices (which is my goal).
Here is what i tried:
When i try to pair both devices with IOCapabilities KeyboardOnly, they behave like they are DisplayOnly and DisplayYes/No but even if i confirm the Passkey with yes, they wont connect.
If i put both devices in Pairable mode, no passkey is asked.
How do i tell bluetoothctl to use a passkey provided by me?
The documentation of bluetoothctl and btmgmt is sadly non existent and i have problems progressing.
Bluetoothctl Manpage
btmgmt Manpage
Device A:
root#PiAlice:/home/alicepi# bluetoothctl
Agent registered
[bluetooth]# agent off //unregister the agent to chose the right IOCaps
Agent unregistered
[bluetooth]# agent KeyboardOnly
Agent registered
[bluetooth]# show
Controller DC:A6:32:99:5C:AC (public)
Name: PiAlice
Alias: PiAlice
Class: 0x00480000
Powered: yes
Discoverable: no
Pairable: no
UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb)
UUID: Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb)
Modalias: usb:v1D6Bp0246d0532
Discovering: no
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller DC:A6:32:99:5C:AC Discoverable: yes
[NEW] Device DC:A6:32:AB:71:D9 bobpi
[CHG] Device DC:A6:32:AB:71:D9 Connected: no
[DEL] Device DC:A6:32:AB:71:D9 bobpi
[bluetooth]# pairable on
Changing pairable on succeeded
[CHG] Controller DC:A6:32:99:5C:AC Pairable: yes
[NEW] Device DC:A6:32:AB:71:D9 bobpi
[CHG] Device DC:A6:32:AB:71:D9 Modalias: usb:v1D6Bp0246d0532
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:AB:71:D9 ServicesResolved: yes
[CHG] Device DC:A6:32:AB:71:D9 Paired: yes
[CHG] Device DC:A6:32:AB:71:D9 ServicesResolved: no
[CHG] Device DC:A6:32:AB:71:D9 Connected: no
Device B:
root#bobpi:/home/bobpi# bluetoothctl
Agent registered
[bluetooth]# agent off
Agent unregistered
[bluetooth]# agent KeyboardOnly
Agent registered
[bluetooth]# show
Controller DC:A6:32:AB:71:D9 (public)
Name: bobpi
Alias: bobpi
Class: 0x00480000
Powered: yes
Discoverable: no
Pairable: no
UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb)
UUID: Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb)
Modalias: usb:v1D6Bp0246d0532
Discovering: no
[bluetooth]# scan on
Discovery started
[CHG] Controller DC:A6:32:AB:71:D9 Discovering: yes
[NEW] Device DC:A6:32:99:5C:AC PiAlice
[bluetooth]# pair DC:A6:32:99:5C:AC
Attempting to pair with DC:A6:32:99:5C:AC
[CHG] Device DC:A6:32:99:5C:AC Connected: yes
Request confirmation
[agent] Confirm passkey 896560 (yes/no): yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device DC:A6:32:99:5C:AC Connected: no
[bluetooth]# pairable on
Changing pairable on succeeded
[CHG] Controller DC:A6:32:AB:71:D9 Pairable: yes
[bluetooth]# pair DC:A6:32:99:5C:AC
Attempting to pair with DC:A6:32:99:5C:AC
[CHG] Device DC:A6:32:99:5C:AC Connected: yes
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device DC:A6:32:99:5C:AC ServicesResolved: yes
[CHG] Device DC:A6:32:99:5C:AC Paired: yes
Pairing successful
[CHG] Device DC:A6:32:99:5C:AC ServicesResolved: no
[CHG] Device DC:A6:32:99:5C:AC Connected: no

Connect and use multiple bluetooth dongles on linux?

Is it possible to connect more than two bluetooth dongles(adapters) to the linux machine and use them for read/write/communication with other external bluetooth devices simultaneously? So that there are will be more than one bluetooth device bluez can recognize and work with in parallel.
To complete #sam's answer as I was looking at doing the them. Here is the demonstration of two bluetooth adapter in Linux with bluetoothctl:
Without any USB Bluetooth dongle on my laptop I see:
[bluetooth]# list
Controller 84:EF:18:1E:5B:8A olivier-ThinkPad-E460 #1 [default]
After I hotplug the USB Bluetooth dongle, I can see:
[NEW] Controller 5C:F3:70:8A:A6:97 olivier-ThinkPad-E460 #2 [default]
[CHG] Controller 5C:F3:70:8A:A6:97 UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Controller 5C:F3:70:8A:A6:97 UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Controller 5C:F3:70:8A:A6:97 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Controller 5C:F3:70:8A:A6:97 UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Controller 5C:F3:70:8A:A6:97 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Controller 5C:F3:70:8A:A6:97 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Controller 5C:F3:70:8A:A6:97 UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Controller 5C:F3:70:8A:A6:97 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[bluetooth]# list
Controller 84:EF:18:1E:5B:8A olivier-ThinkPad-E460 #1 [default]
Controller 5C:F3:70:8A:A6:97 olivier-ThinkPad-E460 #2
To select the USB Bluetooth dongle which has for MAC address 5C:F3:70:8A:A6:97:
[bluetooth]# select 5C:F3:70:8A:A6:97
[bluetooth]# list
Controller 84:EF:18:1E:5B:8A olivier-ThinkPad-E460 #1
Controller 5C:F3:70:8A:A6:97 olivier-ThinkPad-E460 #2 [default]
We can see the USB adapter is now marked as [default].
When I scan for bluetooth devices, I can see it use the USB dongle:
[bluetooth]# scan on
Discovery started
[CHG] Controller 5C:F3:70:8A:A6:97 Discovering: yes
[NEW] Device A0:E6:F8:37:AE:94 5AAA=mRwb6qK$v_~xL5O#uK)AqfHK
[NEW] Device 54:E5:F7:BC:4C:D9 54-E5-F7-BC-4C-D9
Same when I want to connect:
[bluetooth]# connect DE:79:A2:A1:E9:FA
Attempting to connect to DE:79:A2:A1:E9:FA
[CHG] Device DE:79:A2:A1:E9:FA Connected: yes
Connection successful
[NEW] Primary Service
/org/bluez/hci1/dev_DE_79_A2_A1_E9_FA/service0008
00001801-0000-1000-8000-00805f9b34fb
Generic Attribute Profile
[NEW] Characteristic
/org/bluez/hci1/dev_DE_79_A2_A1_E9_FA/service0008/char0009
00002a05-0000-1000-8000-00805f9b34fb
Service Changed
Notice the hci1 in the DBUS path: /org/bluez/hci1/dev_DE_79_A2_A1_E9_FA
yes its possible. Use bluetoothctl command line tool provided by bluez to select adapter.
Each device will recognized with different adapter. You can choose the adapter and give commands

[RPi3][Bluez] Managed to connect to a BLE device but can't list GATT attributes

I am doing a project where I need to create communication between two Raspberry Pi 3 on stretch (RPi) wirelessly with callback functionalities using C++ code. The first is supposed to send data to the second one. I decided to create a bluetooth connexion between the two using the on-board bluetooth-chips.
So first I decided to compile Linux Bluetooth Stack: Bluez on both RPi from source, version 5.50. Following this tutorial : https://learn.adafruit.com/install-bluez-on-the-raspberry-pi/installation on Adafruit. I managed to send a message from one pi to another using these codes :https://people.csail.mit.edu/albert/bluez-intro/x502.html. But to read a message sent by the client, I have to call the function "read(client, buf, sizeof(buf))" as shown in the server code which is a bit restrictive. I want to be notified whenever a message is received so that a callback function can be called. I saw it could be done by enabling notifications on the GATT Characteristics used for the communication.
This level of specification is not really shown on the C++ codes I got from https://people.csail.mit.edu/albert/bluez-intro/x502.html. After having improved my knowledge on GATT with this : https://www.novelbits.io/bluetooth-gatt-services-characteristics/ , I decided to follow Tony D's youtube tutorial on how to use Bluez APi
https://www.youtube.com/watch?v=5fQR2PHMDWE.
To make it easier, I decided to left one RPi aside and tried to connect a Bluetooth audio headset JBL T450BT which use Bluetooth 4.0, so it is supposed to support Bluetooth Low Energy.
On bluetoothctl here's the problem, I manage to power on the controller, scan on and detect the headset. I then trust, pair and connect. In GATT menu, I enter the command : list-attributes [dev address]. Bluetoothctl prints no error but returns nothing and is ready to receive other command lines.
sudo bluetoothctl
[bluetooth]# show
Controller XX:XX:XX:XX:XX:XX (public)
Name: VoitureRPi
Alias: VoitureRPi
Class: 0x004c0000
Powered: yes
Discoverable: no
Pairable: yes
UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb)
UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
UUID: Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb)
Modalias: usb:v1D6Bp0246d0532
Discovering: no
[bluetooth]# scan on
Device 78:44:05:BC:12:0C JBL T450BT
[bluetooth]# trust 78:44:05:BC:12:0C
[CHG] Device 78:44:05:BC:12:0C Trusted: yes
Changing 78:44:05:BC:12:0C trust succeeded
[bluetooth]# pair 78:44:05:BC:12:0C
Attempting to pair with 78:44:05:BC:12:0C
[CHG] Device 78:44:05:BC:12:0C Connected: yes
[CHG] Device 78:44:05:BC:12:0C UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C ServicesResolved: yes
[CHG] Device 78:44:05:BC:12:0C Paired: yes
Pairing successful
[CHG] Device 78:44:05:BC:12:0C ServicesResolved: no
[CHG] Device 78:44:05:BC:12:0C Connected: no
[bluetooth]# connect 78:44:05:BC:12:0C
Attempting to connect to 78:44:05:BC:12:0C
[CHG] Device 78:44:05:BC:12:0C Connected: yes
Connection successful
[CHG] Device 78:44:05:BC:12:0C ServicesResolved: yes
[JBL T450BT]# menu gatt
[JBL T450BT]# list-attributes 78:44:05:BC:12:0C
[JBL T450BT]#
From there I get no answer from bluetoothctl but no error as well, as I told you. I am not able to discover services/characteristics.
On the youtube tuto I followed,it was told that the GATT services and Characteristics discovery was done during the pairing/first connexion. I assume that the Pi intends to do it but fails. That's maybe why I get the sequence :
connected: yes, ServicesResolved: yes Paired successfully and then ServicesResolved: no, connected no. Nothing like : [NEW] XXX Service or Characteristcs is shown.
I don't think the problem comes from the headset because it does the same thing on other devices I connect to. I have both pulseaudio and bluealsa packages installed on the RPi.
As mentionned in this tuto
Here the bluetooth status :
systemctl status bluetooth
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-11-08 11:29:38 CET; 27min ago
Docs: man:bluetoothd(8)
Main PID: 2646 (bluetoothd)
Status: "Running"
CGroup: /system.slice/bluetooth.service
└─2646 /usr/local/libexec/bluetooth/bluetoothd --experimental
Here's what hciconfig gives :
hciconfig -a
hci0: Type: Primary Bus: UART
BD Address: B8:27:EB:A8:0C:20 ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:11205 acl:76 sco:0 events:520 errors:0
TX bytes:219869 acl:433 sco:0 commands:150 errors:0
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH SNIFF
Link mode: SLAVE ACCEPT
Name: 'VoitureRPi'
Class: 0x4c0000
Service Classes: Rendering, Capturing, Telephony
Device Class: Miscellaneous,
HCI Version: 4.1 (0x7) Revision: 0x168
LMP Version: 4.1 (0x7) Subversion: 0x2209
Manufacturer: Broadcom Corporation (15)
Here's also what the D-Bus introspection tool returns :
busctl tree org.bluez
└─/org
└─/org/bluez
└─/org/bluez/hci0
└─/org/bluez/hci0/dev_78_44_05_BC_12_0C
├─/org/bluez/hci0/dev_78_44_05_BC_12_0C/fd1
└─/org/bluez/hci0/dev_78_44_05_BC_12_0C/player0
For people who got problems with pairing and connecting, this source was a huge help :https://www.sigmdel.ca/michel/ha/rpi/bluetooth_02_en.html
Anyway so that's my problem. I want to access Characteristics and their UUID's to be able to modify their permission or to create a new service with its own characteristics suited to my project.
To this point I think this is the only way to implement a notifier with a callback in a bluetooth communication. Maybe I'm wrong. Do you have any clue whatsoever ? :)
Thanks to A.Baur, the "--experimental" option was the last missing thing.
My system:Debian 10 + KDE
Installed:
- bluez-*
- bluetooth
- pulseaudio-module-bluetooth
Steps:
1. stop bluetooth service: >sudo systemctl stop bluetooth
2. modify: /etc/init.d/bluetooth ; by adding to the line:
SSD_OPTIONS="**--experimental** --oknodo --quiet --exec $DAEMON -- $NOPLUGIN_OPTION"
3. start bluetooth service: >sudo systemctl start bluetooth
4. connect to Bose QC35 II by bluetoothctl or other GUI tool.
I got it working in RPi with python examples of advertisement and gatt server from bluez-5.50. I used nRF tool to test it.

Siri remote (ATV4) with raspberry pi 3 bluetooth

I have a raspberry pi 3 and a 4th generation apple tv remote.
I don't understand why I am unable to see the remote when I scan with the raspberry pi using "hcitool scan" command.
I have to say that I can see other bluetooth device during the scan but never the remote.
I can see the remote when I scan with my iPhone.
My ATV4 is unplugged and i have put the remote on pair mode (menu + volume up)
What is wrong ? Thanks
I've been looking into this for a little while, and my conclusion so far is that there may be something a bit non-standard or unusual about the bluetooth in the Siri Remote / 4th generation Apple TV remote. Certainly it manages to upset LightBlue on my Mac and iPhone in slightly different ways.
If I use bluetoothctl, the remote does show up and I can connect to it (at least if I hold menu+volumeup for 5 seconds whilst bluetoothctl has discovery enabled):
root#raspberrypi:/home/pi# bluetoothctl
[NEW] Controller B8:27:EB:6C:15:98 raspberrypi [default]
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:6C:15:98 Discovering: yes
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[NEW] Device 78:9F:70:5E:A3:14 DJ7Q6MZ9GQQT
[NEW] Device 67:8F:99:BC:EE:C5 67-8F-99-BC-EE-C5
[CHG] Device 67:8F:99:BC:EE:C5 RSSI: -64
[CHG] Device 67:8F:99:BC:EE:C5 RSSI: -44
[CHG] Device 67:8F:99:BC:EE:C5 RSSI: -64
[CHG] Device 67:8F:99:BC:EE:C5 RSSI: -44
[bluetooth]# connect 78:9F:70:5E:A3:14
Attempting to connect to 78:9F:70:5E:A3:14
[CHG] Device 78:9F:70:5E:A3:14 Connected: yes
Connection successful
[CHG] Device 78:9F:70:5E:A3:14 UUIDs:
00001800-0000-1000-8000-00805f9b34fb
00001801-0000-1000-8000-00805f9b34fb
0000180a-0000-1000-8000-00805f9b34fb
0000180f-0000-1000-8000-00805f9b34fb
00001812-0000-1000-8000-00805f9b34fb
0000181e-0000-1000-8000-00805f9b34fb
8341f2b4-c013-4f04-8197-c4cdb42e26dc
[CHG] Device 78:9F:70:5E:A3:14 Appearance: 0x03c0
[CHG] Device 78:9F:70:5E:A3:14 Modalias: bluetooth:v004Cp0266d0000

Resources