3

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?

T0maas
  • 422
  • 2
  • 12
  • Are you saying that those commands do **NOT** work in your terminal at the command line prompt? It might sound weird, but have you wrapped the first form of the bluetoothctl command inside a pair of ( ), i.e. **echo 1234 | ( bluetoothctl pair XX:XX:XX:XX:XX:XX 2>&1 )** ?? – Eric Marceau Jan 11 '23 at 22:05

1 Answers1

0

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:-

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72