Bluetooth pairing without GUI - linux

I need to use a USB Bluetooth dongle on a linux server.
Actually it works and I can discover other bluetooth devices, but if I try to connect with one of them (with rfcomm) it says Can't connect RFCOMM socket: Connection refused.
I think that the problem is the pairing, because when I type the same command on desktop systems, it asks the passkey to me, in a dialog window (not in the terminal).
So the question is: how can I pair a device without a desktop environment?
Thanks in advice.

This command works for me:
echo [PIN] | bluez-simple-agent hci0 [BT_MAC_ADDRESS]

If your device is already paired, then to request pairing again, commands as below. Or else error mesage as Creating device failed: org.bluez.Error.AlreadyExists: Already Exists
To remove pairing: bluez-test-device remove XX:XX:XX:XX:XX:XX
To pair again : bluez-simple-agent hci0 XX:XX:XX:XX:XX:XX
If you happen to have than 1 bluetooth hardware and would like to use second one, use hciconfig to find adapter name and then use that name in place of hci#. Command as below
bluez-simple-agent hci# XX:XX:XX:XX:XX:XX

Related

How to pass PIN to bluetoothctl

I am trying to pair device using bash script. I want to do it automatically without prompting user to enter PIN.
I tried this over stdin:
echo 1234 |bluetoothctl pair XX:XX:XX:XX:XX:XX
And this as parameter:
bluetoothctl pair XX:XX:XX:XX:XX:XX 1234
But nothing worked.
I need to provide pin because i am trying to pair with HC-05 module.
Or is there some alternative to bluetoothctl on raspberry pi OS, that can do what I want?
You can try to overcome this by changing the IO capability on your device so that you don't even get a prompt in the first place. You have two options when launching bluetoothctl:-
bluetoothctl --agent DisplayOnly
bluetoothctl --agent NoInputNoOutput
This will make it so that when pairing, the remote device will know that you don't even have the capability to do any inputting on your device, and therefore the prompt will switch to the remote device or to JustWorks pairing if the other device has no input capability as well.
Have a look at the links below for more information:-
Raspberry BLE encryption/pairing
Linux command line how to accept pairing without pin
BLE pairing the Raspberry Pi 3B model
Bluetoothctl set passkey
Automatically accept Bluetooth pairings

OpenSUSE 15.0 LEAP pulseaudio unable to detect bluetooth speaker

I would like to stream my music through my Bluetooth speaker but PulseAudio can't see the speaker. When I open the sound settings (pavucontrol) I can't change the output device to my speaker since it's not displayed.
What I already checked
The speaker is paired and connected through the Bluetooth interface in GNOME. I verified the connection using the bluetoothctl tool and made sure that the device is connected and trusted by OpenSUSE.
I checked if PulseAudio can see the device through the command line using pactl list sources short and pactl list sinks short and it's not there either.
I verified if PulseAudio has the right Bluetooth addon installed and it has.
Removing the configuration in ~/.config/pulse doesn't help
This question: Pulseaudio not detecting bluetooth headset couldn't help me either.
It worked a couple months ago without any issue but now it doesn't. Any advice to force PulseAudio to recognize my Bluetooth speaker?
Setup:
UE Boom Bluetooth speaker
GNOME OpenSUSE Leap 15.0
Pulseaudio 11.1
BlueZ 5.48
Try these steps to resolve the bluetooth audio issue on Opensuse Linux- These would work in ubuntu and other linux too. I am running on Opensuse linux 15.
First comment out the line
load-module module-bluetooth-discover
by editing the
sudo vim /etc/pulse/default.pa
Now you would need to reboot after this change is done. After rebooting,
we configure the bluetoothctl by running the following sequence of commands in a terminal:
> pactl load-module module-bluetooth-discover
> bluetoothctl
>> power on
>> agent on
>> default-agent
>> discoverable on
>> scan on
scanon will return with the name of the bluetooth speaker along with a code in the format '11:11:11:11:11:11' - thats ur bluetoooth speakers id. Note that down and use it in the next command trust and connect.
>> trust 11:11:11:11:11:11
>> connect 11:11:11:11:11:11
>> scan off
Do not close this terminal.
And these are all thats required to connect to a bluetooth speaker/headphone.
YOu can put the above in a script say - connectbluettooth.sh and run it everytime you login.
Last step change the speakers settings, your applications uses by running the below command:-
pavucontrol - Change the default audio device to the bluetooth speaker.
You can see my bluetooth speaker - 'Juarez' set in the pavucontrol tool in the screenshot.

beaglebone black wireless bluetooth AVRCP

I am working on a project with the beagle bone black wireless, where I need to be able to send music control commands to a phone. Note, I don't want to stream music to my beaglebone. I have spent about a week looking online, and found very little about this.
The OS for the beaglebone is Debian Jessie. I can get things like hci0tool, Bluetoothctl, hciconfig to work. I can detect and pair to a device. It seems though that my connection only lasts for the pairing process, and fails every time afterwards.
My current process is executing:
sudo su
bluetoothctl
power on
agent on
default-agent
scan on
I get the mac address
scan off
pair <MAC Address>
trust <MAC Address>
connect <MAC Address>
As of now pairing and trust succeed, though the connection ends after pairing finishes. And I have no idea of where to start for sending a command to a phone.
Connect call on Device1 interface will tries to connect all the profiles supported between the device and adapter. This happens by negotiating or exchanging the supported profiles.
Connection may not be possible when Adapter doesn't support the minimal requirement of profiles which is needed by the Device. In this case, you may need A2DP provider in adapter end to get connection successful. Yes, this is contradictory to this statement.
If you don't want to connect with all the profiles between Device and Adapter, then you can use ConnectProfile method in Device1 interface.
But bluetoothctl doesn't provide commands to achieve neither ConnectProfile nor you AVRCP commands.
You need to use D-Bus calls to get the communication with Bluetoothd. If your application is command line/shell based, you can use dbus-send/gdbus commands to address the D-Bus interface.
Although bluez-tools implements media control AVRCP commands, it doesn't provide any utility which uses it. Either you can compile bluez-tools as library and develop application using the media control API or use dbus-send/gdbus.
I have started with some samples using GDBUS, but not yet for AVRCP controls. See here : https://gist.github.com/parthitce
and Documentation here: https://www.linumiz.com/category/blog/

Issue with Bluetooth connection. Raspberry pi3 and nodejs 7.4.0

Ass everyone saying in their first posts "I'm new one" and trying to figure out one complexity.
I want to scan and create list of available wifi networks in Raspberry area and send the list to the phone via bluetooth.
Next - select one of the networks in the list on the phone, enter a password to selected network and send back via bluetooth to Raspberry
I'm using Raspberry pi3 with bluetooth on board, Raspbian OS and nodejs v7.4.0
I choose wifi-control to work with wifi network and it works greate. One thing - I should run npm run with sudo to get all networks, not just current one;
Then I'm trying to work with bluetooth via bluetooth-serial-port lib.
First of all I did all preparations that was written in documentation.
var btSerial = new (require('bluetooth-serial-port')).BluetoothSerialPort();
btSerial.inquire();
And it does nothing. At least I don't see any effect - my phone doesn't "see" Raspberry in available bluetooth devices list;
I thought that my Raspberry has porblems with bluetooth, but then I run
bluetoothctl -> power on -> discoverable on
And Raspberry appeared on phone.
What should I do to "turn on" Bluetooth control and add my Raspberry to list of available bluetooth devices?
Peace!
Got the exact same problem. My solution (which might or might not be fitting for your needs) was to pair the phone via bluetoothctl beforehand. (this already is you why this solution kinda sucks: you can't come and use a different phone/pi the next day, stuff got completely screwed when changing to a different pi :D)
Oh and the main script should run as root, else all of this wont work.
1) Pairing your device
$ bluetoothctl
[bluetoothctl] agent on
[bluetoothctl] discoverable on
[bluetoothctl] pairable on
[bluetoothctl] scan on
(now you turn on your bluetooth on your phone and search for devices, in bluetoothctl you should see your device and mac to be shown)
[bluetoothctl] pair XX:XX...(MAC of your phone)
(phone is going to show the "yo this device wants to pair"-dialog and bluetoothctl wants you to confirm the pairing too)
Now you can always connect to the pi via bluetooth, if it is discoverable or not. (I'm using Serial Bluetooth Terminal)
2) Actual talking between devices
NONE of the npm packages supposed to work with bluetooth worked for me. Not a single one. So in the end I used rfcomm and it's ability to start a program on connection. Together with serialport I let rfcomm run node myscript.js, which establishes the actual serial connection like so:
2.1) rfcomm waiting for connections
const rfcommProc = spawn(
'rfcomm',
['watch', 'hci0', '1', 'node', `${__dirname}/myscript.js`]
);
2.2) myscript.js opening the port
const port = new SerialPort('/dev/rfcomm0', spError => {
if (spError) {
process.send(spError);
}
})
Look up on the npmjs-page how to receive and send stuff now.(:
Hope this gives you some ideas and/or helped.
3) Note
The bluetooth service starts quite late. Making a service requiring it didn't do the job for me, but adding it to rc.local seems to be "late enough" to have it running and listening on startup.

Using Bluetooth low energy in linux command line

I am working on using the Bluetooth low energy modem with Linux. I am using the command line option for that i.e. hcitool . I am able to the find the devices using the command: $ hcitool scan
It is working fine for me, also I am able to broadcast my device using :
sudo hciconfig hci0 leadv
It is also working fine. But I want to add the services and characteristic to the modem device which can be detected by other device. I have tried sdptool add but it is not working for me. Does anyone know how to add the services and characteristics to the peripheral using the command line tools in ubuntu?
Edit: My modem is broadcasting but not able to explore the services and characteristic to the other BLE device. Now I am able to set the name of device using hcio name command
Edit: Now I am able to render the services and characteristic, by simultaneously running sudo hcidump command. But I am not able to track from where I am getting those services and characteristics. One definite observation is those services are rendering from the machine.
SDP is absent in BLE. Broadcast/advertise frame and GATT client/server are used instead.
Several links:
BlueZ gatttool: command line tool to run common GATT procedures
BlueZ GATT's ready profiles
hint: DBUS
GATT and DBUS example
How can I connect to the FitBit Zip over Bluetooth 4.0 LE on Linux with bluez?
Bluetooth Low Energy: listening for notifications/indications in linux
http://comments.gmane.org/gmane.linux.bluez.kernel/29547
I used to broadcast BT services by following this article. This page not only shouws you how to advertise a profile, but also gives you an example on how to implement the HSP profile.
To know the bt class you need to announce, you can check this other page.

Resources