I am trying to pair my custom made BLE device with a Raspberry Pi 4, using the bluepy library, programmatically. I do not want to press "accept" or type "yes" whenever I try to pair. I want it to accept pairing automatically. However, whenever I try to pair using the bluepy pair(), method, a prompt shows up asking to accept or reject pairing, every time.
This question is similar to Automatically accept bluetooth pairings, however, none of the solutions seem to work.
I've run the following code in a terminal:
sudo bluetoothctl
pairable on
agent NoInputNoOutput
default-agent
which have been suggested other places. When I do this inside a terminal, I instead get a text prompt, forcing me to type "yes" in order to accept the pairing. So I still get the prompt, just in a different place. Is there a way to make bluetoothctl automatically accept new pairings? Maybe there is some documentation on how to set up the bluetoothctl agent in such a way that it does not prompt the user for every new device? I've tried to use subprocess in Python to script the bluetoothctl input, however, it always fail to when it comes to typing "yes" on the annoying prompt.
I have also tried:
sudo hciconfig hci0 piscan
sudo hciconfig hci0 sspmode 1
However, this results in a "Authentication Failed" error using the Bluepy library. Now there is no prompt, the pairing is simply rejected.
In the source code I basically do:
from bluepy.btle import Peripheral
peripheral = Peripheral('aa:bb:cc:dd:ee:ff')
peripheral.pair()