hcitool cc and hcitool auth returns Input/output error - bluetooth

I have successfully set up and enabled Bluetooth on my server running Debian Buster. That in itself is quite an achievement. Anyhow, I am trying to use a Node package called node-bluetooth-serial-port to connect to a tiny Bluetooth speaker with a display. I manage to list/scan devices, but it cannot send anything to the device. I'm thinking this is because my server hasn't been paired with the device yet.
$ hcitool scan
Scanning ...
11:22:33:44:55:66 TimeBox-mini-audio
$ sudo hcitool cc 11:22:33:44:55:66; sudo hcitool auth 11:22:33:44:55:66
HCI authentication request failed: Input/output error
So hcitool can find the device, but it cannot connect to it, for some reason. dmesg doesn't show me any errors what so ever.
I have tried to pair with other devices (like my phone), but that doesn't work either.
The device does not require a 4-digit pin to auth.
What can I do here?

Related

Connecting two raspberry pi through bluetooth with bluez

I'm trying to use this API: https://www.linumiz.com/bluetooth-connectdevice-without-scanning/ to make a connection between two Raspberry PI. I'm using this program like a server such as:
pi#raspberrypi:~/bluetoothC $ sudo ./bin/bluez_adapter_connect
Adapter is Powered "on"
and then, in the client side:
pi#raspberrypi:~/bluetoothC $ sudo ./bin/bluez_adapter_connect
B8:27:EB:9F:91:A7
Adapter is Powered "on" Unable to get result:
GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Method
"ConnectDevice" with signature "a{sv}" on interface
"org.bluez.Adapter1" doesn't exist
But I don't understand this error. I'm doing this correctly? If not, what I have to do?
As mentioned in the article, ConnectDevice is the new adapter API introduced in BlueZ 5.49. Refer release notes here for more details.
This API is still marked as experimental, so you need to run bluetoothd daemon in experimental mode, i.e by passing "-E" as extra argument when starting bluetoothd.
So you need,
BlueZ 5.49 or later
Run bluetoothd daemon with "-E" option

gatttool and hcitool on Linux

I'm trying to connect to a device using gatttool on Linux. I run hcitool lescan to get the device MAC address, and then gatttool -i hci1 -b <macaddr> -t random -I. Then I type connect. I see [CON] as expected, but the problem is that it disappears automatically after about 1s, with no error messages. I have been searching for hours, but I don't see why that is so?
Note: I have run hcitool lecc before running gatttool one time just to try it, but it seems to me that since then, gatttool connection is not working properly anymore (unexpected disconnection as explained above). Is it because I have used hcitool lecc? If yes, is there a way to "undo" it?
Not sure if this helps you because I'm seeing this behavior on my Raspberry Pi (an up-to-date wheezy version) and bluez 5.18 (released April 2014.)
I can connect to my BLE peripheral from the command line after doing an lecc without any problems. I don't think you need to reset after an lecc. Regardless, if you do want to reset your BT dongle because it is in some funky state, look at this excellent step-by-step guide to reset the BT dongle. I have followed these steps with consistent results.
I can connect and query say primary but more often than not, the connection drops before I can manually type in primary. See the results below. If I use the up/down arrows after connecting to quickly scroll to primary, I am able to see primary services offered by this peripheral without any problems.
~ $ sudo gatttool -I -i hci0 -m 48 -b 20:CD:39:A8:11:AF
[20:CD:39:A8:11:AF][LE]> connect
Attempting to connect to 20:CD:39:A8:11:AF
Connection successful
[20:CD:39:A8:11:AF][LE]> primary
Command Failed: Disconnected

Can't connect to OBD-II device from node-bluetooth-obd

I'm attempting to connect via node.js to an ELM327 Bluetooth OBD-II adapter using Eric Smekens node-bluetooth-obd package, but I'm getting an error I'm not sure how to debug. I am doing this on a Beagle Bone Black running Ubuntu. I'm able to pair with the device using bluez-simple-agent:
sudo bluez-simple-agent hci0 00:0D:18:A0:4E:35
And I've updated the MAC address in the second line of the Readme.md example to match the MAC address of the device:
var btOBDReader = new OBDReader('00:0D:18:A0:4E:35', 14);
However, when I run the script, I get this error:
Error with OBD-II device: Error: Cannot connect
I'm still pretty new with bluetooth comms, so I don't really know where to start debugging this. Any suggestions?

How to setup serial communication in Processing to /dev/rfcomm0

I am trying to perform serial communication on between Ubuntu 12.04 and a JY-MCU bluetooth serial module connected to an Arduino.
I have created this configuration in /etc/bluetooth/rfcomm.conf
rfcomm0 {
# # Automatically bind the device at startup
bind yes;
#
# # Bluetooth address of the device
device 00:12:11:19:08:54
# # RFCOMM channel for the connection
channel 1;
# # Description of the connection
comment "Linvor Bluetooth Module";
}
I can use putty to communicate with the /dev/rfcomm0 serial port and this works perfectly.
However, despite many attempts I simply cannot see how to create a serial port in Processing that works in any way.
For example :
println(Serial.list());
prints nothing at all.
If I execute:
String portName = "/dev/rfcomm0";
myPort = new Serial(this, portName, 9600);
println(myPort);
I see this in the monitor:
processing.serial.Serial#1712651
But if I then call:
myPort.write('9');
I get an exception:
java.lang.NullPointerException
at processing.serial.Serial.write(Serial.java:572)
...
I can't understand why this fails. I have been following all the instructions from Tom Igoe's "Making Things Talk", but this just does not work the way he says...
Any help would b great!
Thanks,
Bob
Aftert searching high and low, I have made this work.
The key issue is that processing uses the rxtx java library (RXTX-2.1-7) for serial communications.
The RXTX wiki says:
"rxtx tries to detect ports on by scanning /dev for files matching any
of a set of known-good prefixes, such as 'ttyS', 'ttym', and since 2.2
'ttyUSB' and so on. "
And since the bluetooth device is named rfcomm* it cannot be detected.
The trick is to create a sym link to fool rxtx (use a ttyS device that is not yet assigned):
$ sudo ln -s /dev/rfcomm0 /dev/ttyS99
Then, connect:
$ sudo rfcomm connect 0
Connected /dev/rfcomm0 to 00:12:11:19:08:54 on channel 1
Press CTRL-C for hangup
At this point the red led on the JY-MCU becomes solid and processing can detect it:
println(Serial.list());
output is:
[0] "/dev/ttyACM0"
[1] "/dev/ttyS99"
So, serial communication can work.
To summarize, the following process will allow a processing script to communicate via a serial port with a JY-MCU device in a BlueZ linux framework
One time setup:
power up the JY-MCU,
use the following command to get its hardware address, mine is 00:12:11:19:08:54
$ hcitool scan
use that to create the /etc/bluetooth/rfcomm.conf file; you'll note that I chose 0 for the rfcomm device , we need that for connection later:
$ cat /etc/bluetooth/rfcomm.conf
rfcomm0 {
bind yes;
device 00:12:11:19:08:54;
channel 1;
comment "Linvor Bluetooth Module";
}
use BlueMan to pair the JY-MCU.
Every time you want to use the JY-MCU
create the sym link:
$ sudo ln -s /dev/rfcomm0 /dev/ttyS99
connect to the JY-MCU:
$ sudo rfcomm connect 0
Connected /dev/rfcomm0 to 00:12:11:19:08:54 on channel 1
Press CTRL-C for hangup
you can now run a processing script and connect to the JY-MCU with
the code:
String portName = "/dev/ttyS99";
myPort = new Serial(this, portName, 9600);
after running the processing script, be sure to CTRL-C at the
command line to disconnect the JY-MCU.
That should do it!
Ciao,
Bob
Just something popped up in my mind.
I had similar problems that were caused due to channel 1 is already used. If you bind to a channel which already is in use, bad things may happen.
sdptool browse local
Use that command to see which channels are available on your Ubuntu device.

Linux command line howto accept pairing for bluetooth device without pin

Is there a way to pair a device in linux without requiring a pin(for testing purposes so I need it to be done w/out human interaction, assuming you have root access)?
bluez-simple-agent seems to require a pin except with some simple devices such as mice.
Entering a PIN is actually an outdated method of pairing, now called Legacy Pairing. Secure Simple Pairing Mode is available in Bluetooth v2.1 and later, which comprises most modern Bluetooth devices. SSPMode authentication is handled by the Bluetooth protocol stack and thus works without user interaction.
Here is how one might go about connecting to a device:
# hciconfig hci0 sspmode 1
# hciconfig hci0 sspmode
hci0: Type: BR/EDR Bus: USB
BD Address: AA:BB:CC:DD:EE:FF ACL MTU: 1021:8 SCO MTU: 64:1
Simple Pairing mode: Enabled
# hciconfig hci0 piscan
# sdptool add SP
# hcitool scan
00:11:22:33:44:55 My_Device
# rfcomm connect /dev/rfcomm0 00:11:22:33:44:55 1 &
Connected /dev/rfcomm0 to 00:11:22:33:44:55 on channel 1
Press CTRL-C for hangup
This would establish a serial connection to the device.
follow steps (CentOs):
bluetoothctl
devices
scan on
pair 34:88:5D:51:5A:95 (34:88:5D:51:5A:95 is my device code,replace it with yours)
trust 34:88:5D:51:5A:95
connect 34:88:5D:51:5A:95
If you want more details
https://www.youtube.com/watch?v=CB1E4Ir3AV4
Try setting security to none in /etc/bluetooth/hcid.conf
http://linux.die.net/man/5/hcid.conf
This will probably only work for HCI devices (mouse, keyboard, spaceball, etc.). If you have a different kind of device, there's probably a different but similar setting to change.
This worked like a charm for me, of-course it requires super-user privileges :-)
# hcitool cc <target-bdaddr>; hcitool auth <target-bdaddr>
To get <target-bdaddr> you may issue below command:
$ hcitool scan
Note: Exclude # & $ as they are command line prompts.
Courtesy
For Ubuntu 14.04 and Android try:
hcitool scan #get hardware address
sudo bluetooth-agent PIN HARDWARE-ADDRESS
PIN dialog pops up on Android device. Enter same PIN.
Note: sudo apt-get install bluez-utils might be necessary.
Note2: If PIN dialog does not appear, try pairing from Android first (will fail because of wrong PIN). Then try again as described above.
~ $ hciconfig noauth
This should do the trick (I'm using bluez 5.23 and there's no more simple-egent and blue-utils). However, I'm trying to look for a way to make changes hciconfig permanent because after power out and then power on, authentication is needed again. So far, the changes in hciconfig still stays the same when you reboot it. it reverts back only when power out. If anybody has found a way to make hciconfig permanent, do let me know!
~ $ hciconfig noauth
It worked for me in "Linux mx 4.19"
The exact steps are:
1) open a terminal - run: "hciconfig noauth"
2) use the blueman-manager gui to pair the device (in my case it was a keyboard)
3) from the blueman-manager choose "connect to HID"
step(3) is normally asking for a password - the "hciconfig noauth" makes step(3) passwordless

Resources