gatttool can't connect to a bluetooth module - bluetooth

I'm trying to connect a bluetooth module to a Raspberry Pi3 using gatttool.
First, I launched gatttool with following command, and tried to connect;
$ sudo gatttool -b (MAC ADDRESS) -I
Then an error message was shown.
Error: connect: Device or resource busy (16)
I searched it and found some solutions. After that, I tried again.
$ sudo gatttool -t random -b (MAC ADDRESS) -I
Then it attempted to connect to the bluetooth module for a while, and showed following error.
Error: connect error: Connection refused (111)
I never heard about a situation that somebody encountered both of these errors. What can I do to solve it?

Related

How to read BLE Advertising Packets without pairing

I need to read advertising packets from BLE sensors that broadcast temperature in an advertising packet every 5 seconds. I was told by the manufacturer that packet will be a GAP Scan Response Event and that I don't have to connect to the device to read this packet.
The sensor's MAC address shows up when I run sudo hcitool lescan
However, when I run sudo gatttool -I -t random -b 06:09:16:41:87:DB this happens:
[06:09:16:41:87:DB][LE]> connect
Attempting to connect to 06:09:16:41:87:DB
Error: connect error: Connection refused (111)
Also when I run sudo gatttool -b 06:09:16:41:87:DB -I and connect, I get:
Error: connect error: Transport endpoint is not connected (107)
How can I read this advertising packet if I am unable to make a Bluetooth connection via gatttool?
Well, if you want to listen to advertising events then you shouldn't connect since advertisements are broadcast. You should just scan. If you use the debugging tools "hcitool lescan" and "sudo btmon" in a separate terminal concurrently then you should see the scan response data.

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

CentOS 7 USB. Connect to Wi-Fi using CLI only

I just installed CentOS 7 [Kernel 3.10.0-514] on my USB stick.
Operating system works fine but I had some problems with my Broadcom 43227 wireless card.
I downloaded driver, patched it, changed code a bit according to the instruction here: https://wiki.centos.org/HowTos/Laptops/Wireless/Broadcom and after many attempts it finally compilled and after loading the driver module into kernel led turned on.
Now I need to connect to my Wi-Fi.
What am I trying to do:
Get wireless interface name using iw dev:
phy#0
Interface wlp2s0
Scan to find WiFi Network using iw wlp2s0 scan | grep SSID
SSID: MyNetworkName
Generate a WPA/WPA2 configuration file using wpa_passphrase MyNetworkName >> /etc/wpa_supplicant.conf
MyNetworkPassword
Connect to WPA/WPA2 WiFi network using wpa_supplicant -B -D wext -i wlp2s0 -c /etc/wpa_supplicant.conf
Successfylly initialized wpa_supplicant
[and in some cases after few minutes]
ERROR #wl_cfg80211_scan: WLC_SCAN error (-22)
Get an IP using dhclient using dhclient wlp2s0
But nohing happens
Ping command : Name or sarvice not known
If I run wpa_supplicant without -B I get some repeating errors:
Device or resource busy
wlp2s0: Failed to initiate AP scan
wlp2s0: Trying to associate with [MAC] (SSID='MyNetName' freq=2462 MHz)
Operation not supported
wlp2s0: Association request to the driver failed
....
if I add -D nl80211 to wpa_supplicant call I get same errors without "Device or resource busy"
What I am doing wrong?

Cannot disconnect BLE connection

From time to time, I end up with a Bluetooth Low Energy connection in a strange state from which I cannot disconnect:
$ sudo hcitool con
Connections:
< LE F1:11:52:84:77:25 handle 70 state 1 lm MASTER
$ sudo hcitool ledc F1:11:52:84:77:25
Could not disconnect: Input/output error
I can't get any information on the connection either:
$ sudo hcitool leinfo F1:11:52:84:77:25
Requesting information ...
Could not create connection: Input/output error
I can't re-connect either (checked the code: the error comes down from l2cap_connect() where it tries to open a socket to this remote address and fails to).
$ sudo gatttool -t random -b F1:11:52:84:77:25 -I
[F1:11:52:84:77:25][LE]> connect
Attempting to connect to F1:11:52:84:77:25
Error: connect: Device or resource busy (16)
The only solution I have so far is to unplug and replug my BLE dongle ;( but that's not very satisfactory...
Is there a command or something to erase that buggy connection?
This is on Linux (Mint 18), and using bluez 5.37.
sudo hcitool ledc <handle>
ledc takes handle as argument not the mac.
type sudo hcitool con to find out the handle of the connection you want to disconnect. Then use that handle as argument of ledc.
Example:
sudo hcitool con
Output:
connections:
<LE XX:XX:XX:XX:XX:XX handle 64 state 1 lm MASTER
To disconnect this connection type:
sudo hcitool ledc 64
I can confirm this problem on Ubuntu 14.04 with BlueZ 5.40 and 5.43.
Workaround 1: Disconnect from the other side.
Workaround 2: Use
sudo hciconfig hciX down
sudo hciconfig hciX up
where hciX is your controller (e.g. hci0). Unfortunately, this will remove all connections.

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.

Resources