How to pass PIN to bluetoothctl - linux

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

Related

Multible bluetooth controller Raspberry Pi

I'm trying to set a Bluetooth dongle as the default Bluetooth controller on my raspberry pi (rather the the internal controller on the board it self).
bluetoothctl is able to display both devices with:
sudo bluetoothctl list
and even change the default with select. This change however is only applied in the bluetoothctl session and is not permanent.
I would like to change the default system wide. So all Bluetooth activity runs over the dongle.

Disable BT pairing security pin on Embedded Linux device

I have an embedded Linux board running a Yocto Linux image containing BlueZ.
I want to activate the HCI bluetooth device advertising mode and disable the pairing security.
I want to scan for the device with my smartphone and connect directly without security PI, just like any Audio device (JBL, ...).
I tried many methods using (bluetoothctl and other tools) but without success.
Is there a way to achieve this?
Thanks in advance,
Talel
Set IOCapability of your device to NoInputNoOutput then pairing will happen but it won't ask for any confirmation similar to BT headsets.
bluetoothctl command line tool has option to set IOCapability. Set capability and check.
$bluetoothctl
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# discoverable on
Changing discoverable on succeeded
[bluetooth]# pairable on
Changing pairable on succeeded
[bluetooth]# agent NoInputNoOutput
Agent registered

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.

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.

Bluetooth pairing without GUI

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

Resources