different connection result in gatttool and bluetoothctl with raspberry pi 3 bluetooth - bluetooth

When I tried to use gatttool and bluetoothctl to connect to a bluetooth device, gatttool got "Connection refused" but bluetoothctl connected to it successfully.
What's the difference between bluetoothctl and gatttool?
How to make gatttool work because I need to use char-write-cmd command in gatttool?
$ ./gatttool -b 00:13:04:0C:6C:26 -I
[00:13:04:0C:6C:26][LE]> connect
Attempting to connect to 00:13:04:0C:6C:26
Error: connect error: Connection refused (111)
[00:13:04:0C:6C:26][LE]> exit
$ bluetoothctl
[NEW] Controller B8:27:EB:07:26:C8 raspberrypi [default]
[NEW] Device 00:13:04:0C:6C:26 MEDXING-NIBP
[bluetooth]# connect 00:13:04:0C:6C:26
Attempting to connect to 00:13:04:0C:6C:26
[CHG] Device 00:13:04:0C:6C:26 Connected: yes
Connection successful
[bluetooth]# info 00:13:04:0C:6C:26
Device 00:13:04:0C:6C:26
Name: MEDXING-NIBP
Alias: MEDXING-NIBP
Paired: no
Trusted: no
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Device Information (0000180a-0000-1000-8000-00805f9b34fb)
UUID: Unknown (0000ffb0-0000-1000-8000-00805f9b34fb)
[bluetooth]# exit

Solution: just add -t random to gatttool command line and it will connect!

Like #Zibri said the required command is:
sudo gatttool -b 00:13:04:0C:6C:26 -t random -I
Also, it is a good idea to update Bluez, here is a good way to do it from "Installing BlueZ from sources" section of https://github.com/getsenic/gatt-python.
#First, consulte the Bluez version with
bluetoothd --version
#If is not the last one indicated on http://www.bluez.org/, continue with the next steps, reeplace <5.50> with the most updated number version.
sudo systemctl stop bluetooth
sudo apt-get update
sudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev libdbus-glib-1-dev unzip
cd
mkdir bluez
cd bluez
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.50.tar.xz
tar xf bluez-5.50.tar.xz
cd bluez-5.50
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-library
make
sudo make install
sudo ln -svf /usr/libexec/bluetooth/bluetoothd /usr/sbin/
sudo install -v -dm755 /etc/bluetooth
sudo install -v -m644 src/main.conf /etc/bluetooth/main.conf
sudo systemctl daemon-reload
sudo systemctl start bluetooth
#Check the new version
bluetoothd --version

Related

Bluetooth connection from Raspberry Pi to Parani SD100- No usable services

I'm attempting to connect my raspberry Pi to a Parani SD1000 RS232 serial adapter. I have configured the Parani and I can successfully connect to it and retrieve data when using my Macbook. I would like to set up the connection using my raspberry pi. I have a raspberry Pi 3 model b+ 32 bit. I wrote a script that uses Pyserial and created a bind to the bluetooth device via sudo rfcomm bind /dev/rfcomm0 XX:XX:XX:XX:XX:XX 1. However, when I use the Raspberry PI OS interface to connect to the bluetooth I get a message that 'Paired successfully, but this device has no services with can be used with the Raspberry Pi and the connection is aborted.
I've looked for other suggestions and tried updating my software as listed elsewhere. To no avail.
sudo apt-get update
sudo apt-get dist-upgrade
sudo rm /etc/udev/rules.d/99-com.rules
sudo apt-get -o Dpkg::Options::="--force-confmiss" install --reinstall raspberrypi-sys-mods
sudo systemctl reboot
I'm not sure which direction I should be looking. I know the Parani is configured correctly so it must be something on the raspberry. Thank you in advance
rfcomm was deprecated back in 2017 by the BlueZ project so I would recommend against using that methodology.
Python3 on Linux supports connecting to a Bluetooth Classic device with a Serial Port Profile (SPP) with its socket library.
There is more information in the following blog: https://blog.kevindoran.co/bluetooth-programming-with-python-3/
There is also support for SPP within the Bluedot Python library: https://www.stuffaboutcode.com/2017/07/python-bluetooth-rfcomm-client-server.html

hcitool lescan Set scan parameters failed: Input/output error

the following command
sudo hcitool lescan
throws the following error:
Set scan parameters failed: Input/output error
I have tried
hciconfig hci0 down
hciconfig hci0 up
and then
service bluetooth restart
service dbus restart
and tried againg. still didnt work.
OS: Ubuntu 18.04
bluez version: 5.48

wifi services not working in ubuntu

I just installed ubuntu and fire this command :
sudo modprobe -rv rtl8723be
sudo modprobe -v rtl8723be ant_set = 1
how to get it back my display?
you should do.
sudo modprobe -rv rtl8723be ant_set = 1
i hope it will work ...
In our company we have this issue just in HP laptop and we solve it in 6 step
1- open software and update icon from the search field
2- go to Additional Drivers go to Realtek Semiconductor.......
3- select the same choice in the picture
4- run this command: sudo apt install
5- run this command: sudo apt update
6- restart your computer
And enjoy :)

How can I use rfcomm to connect to multiple android smartphones to my Raspberry Pi 3?

I am trying to connect my Raspberry Pi 3 to three android phones through Bluetooth. I want to use the input of the phones in a python code, but before I start coding I have to make sure I can connect all three phones to the Raspberry Pi 3.
The following stuff I did was:
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo rpi-update
sudo apt-get install python3
sudo apt-get install python-bluetooth
sudo nano /etc/systemd/system/dbus-org.bluez.service
Changed the next two lines:
ExecStart=/usr/lib/bluetooth/bluetoothd -C
ExecStartPost=/usr/bin/sdptool add SP
I am using the BlueTooth Serial Conntroller app on the smartphones.
Next I connect through sudo rfcomm listen hci0 which works fine.
I check the connection with minicom -D /dev/rfcomm0 and that works as well. I can send commando's with the app and it shows on the terminal on my Raspberry Pi.
Next, while that connection is active, I try to connect the second phone with sudo rfcomm listen hci2 which connects for a moment on the phone, but on the screen it quickly gives me the message
Can't create rfcomm TTY: address already in use
So I'm thinking it's because I'm using channel 1. So I try sudo rfcomm listen hci2 2 which displays it's waiting on channel 2. But that doesn't work either.
I have checked if I can connect to the second phone on the first channel (when it's free) and it works.
So my question is:
How can I use rfcomm to connect to multiple android smartphones?
Or is there another better way knowing that I want to use Python to use the input?
I had this same exact problem, and this is how I solved it: sudo rfcomm listen /dev/rfcommX 1 where X starts at 0 and increments by 1 for every device you want to connect.

Bluetooth sniffer: How can I install btmon on raspberry Pi?

A kind person said that btmon is a useful tool to exam Bluetooth packets.
I want to use btmon in Raspberry Pi but the tool seems to be not installed by default.
Does anyone know that how to install the tool? I am looking for the information for a long time, but I cannot find it.
Thanks.
P.S.
I can use hcidump. However, I guess that btmon is a more user-friendly tool.
These instructions install both bluez and btmon.
http://www.elinux.org/RPi_Bluetooth_LE
Here is a summary of the instructions in case the link changes.
Install libraries
sudo apt-get install libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev libical-dev libreadline-dev libudev-dev libusb-dev make
Download the source files
mkdir -p work/bluepy
cd work/bluepy
wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.30.tar.xz
tar xvf bluez-5.30.tar.xz
Compile the file
cd bluez-5.30
./configure --disable-systemd
make
sudo make install
Make sure USB device is seen so run the command
lsusb
After running lsusb you may get something like this.
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0a5c:21e8 Broadcom Corp.
Make sure the Bluetooth adapter is up.
sudo hciconfig hci0 up
To see if any Bluetooth LE devices are nearby run. Ctrl-C to stop command.
sudo hcitool lescan
You can now run btmon with hcitool.
./btmon &
hcitool lescan

Resources