1

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()
2
  • Is this similar to: stackoverflow.com/a/66403748/7721752 ?
    – ukBaz
    Jun 9 at 13:19
  • 1
    Thanks @ukBaz. It helped. I am now using the dbus interface, with a custom python agent which does not require user authorization. I am running the dbus main loop in a separate thread than bluepy, but bluepy seem to work together with that custom agent.
    – robino16
    Jun 14 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.