BlueZ bluetoothctl on Raspbian Jessie, connecting a Raspberry Pi to a Sphero - bluetooth

When trying to connect to a Sphero (from Orbotix) through Bluetooth, on a Raspbian Jessie fully updated:
if I do (being root, with Sphero paired and trusted)
# bluetoothctl
[bluetooth]# connect {sphero-mac-address}
[CHG] Device {sphero-mac-address} Connected:yes
[CHG] Device {sphero-mac-address} Connected:no
As you can see the connection fails
but if I do instead
# rfcomm connect /dev/rfcomm0 {sphero-mac-address}
Connected /dev/rfcomm0 to {sphero-mac-address} on channel 1
The connection succeeds, and the Sphero appears connected in bluetoothctl also, afterwards.
What do I do wrong with bluetoothctl connect?

i have the same phenomenom on raspberry pi 3 Jessie when i forgot to do
pulseaudio --start
before bluetoothctl

Related

BLE connection established by bluetoothctl disconnect automatically

I have 2 raspberry pi. I set them as ble (bluetooth low energy) gatt server and client to communicate to each other.
On the server-side, I use https://github.com/Jumperr-labs/python-gatt-server to establish the GATT server; on the client-side, I use bluetoothctl to connect to the server-side (as follows)
[bluetooth]# connect C0:EE:40:3A:D0:45
Attempting to connect to C0:EE:40:3A:D0:45
[CHG] Device C0:EE:40:3A:D0:45 Connected: yes
[ABCDEF123456789
[CHG] Device C0:EE:40:3A:D0:45 Name: ABCDEF123456789
[ABCDEF123456789
[CHG] Device C0:EE:40:3A:D0:45 Alias: ABCDEF123456789
[ABCDEF123456789
[CHG] Device C0:EE:40:3A:D0:45 ServicesResolved: yes
[ABCDEF123456789
Failed to connect: org.bluez.Error.NotAvailable
[ABCDEF123456789
[CHG] Device C0:EE:40:3A:D0:45 ServicesResolved: no
[ABCDEF123456789
[CHG] Device C0:EE:40:3A:D0:45 Connected: no
[bluetooth]#
However, the ble connection always disconnects automatically after the connection just established; on the other hand, if I use hcitool to connect to the server-side (as follows), it can successfully connect.
root#raspberrypi:~# hcitool lecc C0:EE:40:3A:D0:45
Connection handle 64
root#raspberrypi:~# bluetoothctl
Agent registered
[CHG] Controller C0:EE:40:3B:39:5D Pairable: yes
[ABCDEF123456789]#
My question is, why the connection established by bluetoothctl break? Is there anything I missed to start a ble connection using bluetoothctl?
Thanks.
By default the RPi is both BR/EDR (classic) and LE Bluetooth. When acting as a BLE peripheral it is good to configure the controller to Bluetooth Low Energy only. It has been discovered that to get a reliable connection to other devices that support both types of Bluetooth, this is required. This configuration change is done in the /etc/bluetooth/main.conf file. Ensure that the file contains the following:
ControllerMode = le
This can also be done on the command line with:
$ sudo btmgmt power off
$ sudo btmgmt bredr off
$ sudo btmgmt power on

Minimal setup for bluetooth SDP in 2021

I have minimal linux system (no GUI, raspberry pi like board, based on buildroot) which should be able to do the following:
Allow all bluetooth clients to pair (no pin) after pressing a button for 60 seconds
Allow connection using SPP (serial port profile)
Endpoint of the SPP should be something like /dev/rfcomm
In an older version of buildroot (setup around 2016) I was able to do this using the following commands executed after the button press:
dbus-daemon &
bluetoothd --compat &
hciconfig hci0 up
hciconfig hci0 noauth
hciconfig hci0 sspmode 1
hciconfig hci0 class 0x080500
hciconfig hci0 name foobar
hciconfig hci0 piscan
sdptool add --channel=22 SP
rfcomm listen /dev/rfcomm0 22
I could then pair from my android phone without pin and connect to the SPP interface using this app. Since then hciconfig, sdptool and rfcomm where deprecated. If I try the above method I can't pair from my phone (got connection refused). Without pairing the SPP stuff can't work obviously.
What would be the preferred way in 2021 to setup a headless system which behaves as described above?

Bluez fails on Raspberry Pi running Jessie Headless

I've run out of tutorials and tricks that worked for others but not for me.
I'm trying to pair a remote bluetooth speaker with my PI Zero.
When I attempt to connect I get the error message:
[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
[bluetooth]#
And the log reports:
org.bluez.Manager.GetProperties() failed:
org.freedesktop.DBus.Error.UnknownMethod: Method "GetProperties" with
signature "" on interface "org.bluez.Manager" doesn't exist
I have no idea where to begin addressing that. The logs also report
Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported:
Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
and
a2dp-sink profile connect failed for XX:XX:XX:XX:XX:XX: Protocol not
available a2dp-source profile connect failed for XX:XX:XX:XX:XX:XX:
Protocol not available
I'm sure there's useful information in there but every time I think I've googled a solution I'm disappointed. Moving the load of the discoverable module until after X11 load didn't work. Purging pulseaudio and reinstalling it didn't help. Any ideas?
Somewhere on some thread someone said that Pulseaudio had to be version 6.0 or greater, which led me down the rabbit hole of installing version 7, which broke on Jessie due to incompatible dependencies.
Ultimately I purged the following:
apt-get purge pulseaudio pulseaudio-module-bluetooth libpulse0
And reinstalled
apt-get install pulseaudio pulseaudio-module-bluetooth
I then unpaired the Alexa from the pi via the Alexa app on my phone
and ran
bluetoothctl
[bluetooth]# remove XX:XX:XX:XX:XX:XX
Reboot and voilĂ , Pulseaudio running and paired on the Pi and working! Only issue I have now is that I can't seem to get it to start automatically on boot. I've added to /etc/rc.local:
su -c 'pulseaudio --start' - pi
echo connect XX:XX:XX:XX:XX:XX | bluetoothctl
su -c 'pacmd set-card-profile bluez_card.68_54_FD_82_A9_BF a2dp' - pi
Well, to be precise, it pairs automatically on boot, but then drops out. If I manually run
pulseaudio --start
and
bluetoothctl
[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# default-agent
[bluetooth]# connect XX:XX:XX:XX:XX:XX
Then all works fine, stays rock solid. Despite the fact that I STILL have these error messages in the log:
cat /var/log/syslog | grep dbus
org.bluez.Manager.GetProperties() failed:
org.freedesktop.DBus.Error.UnknownMethod: Method "GetProperties" with
signature "" on interface "org.bluez.Manager" doesn't exist
Unable to contact D-Bus: org.freedesktop.DBus.Error.NotSupported:
Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

bluetooth pairing and connection from command line

I want to connect and pair to available nearby bluetooth devices from command line in linux.
I have searched through internet, and found that we can pair through simple-agent, but it is not available in my device.
following commands are available in device:
hcitool, hciconfig, hcidump, sdptool, l2ping, rfcomm.
for connecting to remote device i am running the following command.
hcitool cc BD_ADDRESS
but above command is connecting the device for a while, and again the device is getting disconnected. in hcidump output , i am seeing the disconnection event. Is there anyway in linux command line through which i can test my bluetooth? What can be the reason for device is getting disconnected after a while?
I saw the same issue once and was able to solve it with the rfcomm command. Try the following:
# rfcomm connect /dev/rfcomm0 00:11:22:33:44:55 1 &
Additionally, it is good practice to enable secure simple pairing and enable page and inquiry scan with the following commands:
# hciconfig hci0 sspmode 1
# hciconfig hci0 piscan
Let me know if you still have problems.

Raspberry Pi Bluetooth LE connection to RedBearLab shield

I am trying to connect to RedBearLab BLE shield from RaspPi. I am using
CSR4.0 USB dongle http://www.adafruit.com/products/1327
Raspberry Pi Rev-B board with Raspbian OS
Bluez-5.11
I have the RedBearLab BLE shield connected to Arduino UNO R3. I am trying to connect to the shield from the RaspPi(attached CSR4.0). But it can't connect - connection attempts time out/resource busy.
Below steps I use
$ sudo hcitool lescan
LE Scan ...
xx:xx:xx:xx:xx:xx BLE Shield
$ sudo hcitool lecc xx:xx:xx:xx:xx:xx
Could not create connection: Connection timed out
Using gatttool doesn't solve the problem either
$ sudo gatttool -b xx:xx:xx:xx:xx:xx --interactive
[ ][xx:xx:xx:xx:xx:xx][LE]> **connect**
Attempting to connect to xx:xx:xx:xx:xx:xx
Error: connect error: Device or resource busy (16)
[xx:xx:xx:xx:xx:xx][LE]>
Thanks a bunch!
Seems like your adapter is busy. Something is using it. Is there any other device connected to your adapter? Try resetting your adapter with:
$ sudo hciconfig hci0 reset
Some BLE devices require a random address at connection time. Try:
sudo gatttool -t random -b xx:xx:xx:xx:xx:xx --interactive

Resources