I will use my Raspberry Pi headlessly, that's why I would like to be able to connect to it with my smartphone in Bluetooth. Hence I need it to pair and trust automatically the device (with or without asking for a PIN).
Because it's not safe to accept any devices continuously (even with PIN, I guess brute-force search can easily be used), I will add a physical button to activate the discoverability of the Pi for a specific time with Python script (I managed to do that).
But to accept and trust any devices, I could not find a solution. There are either obsolete or still require to trust the device from the RPi. I am running on
"Raspbian GNU/Linux 10 (buster)" hence
bluetooth-agent function is not available anymore.
I tried the solution on this post, but the RPi still ask me to trust the device. Moreover, if I click on accept I got an error:
Connection failed -
GDBus.Error.org.bluez.Error.Failed: Protocol not available.
Try to connect manually
(the RPi ask me to trust the device after I click on Pair on my phone).
I then tried to set a PIN for any devices following this post, but unfortunately, it uses the
So how to achieve:
When the RPi is discoverable, accepting AND trusting any device without asking on the RPi. The RPi can (or not) ask for a PIN to the device (should be activated from startup).
I am not really familiar with Bluetooth, so I don't understand everything (and I don't like that ^^'), for example, what are agent, bluetoothctl, bluez...?
PS: for my tests, I am using a phone on Android 11.
I followed the infos and code given by @ukBaz on that post, unfortunately, it doesn't work as expected. When I run the script and try to connect, I have a message on my phone asking for pairing with a 6-digit PIN. If I accept, then a Message window (GUI) appears on the RPi asking me to accept the connection. That I don't want because, in future, I'll run the RPi headlessly. Moreover, if I click on accept on that window, I have the previous error (Protocol not available).
I added some displays in the
set_trusted function. So the
Trusted property is indeed set to one, but my device is not paired.
RequestConfirmation (/org/bluez/hci0/dev_MAC_ADDR, 985379)
Set trusted function
Trusted before: 0
Set trusted function -- END
Moreover, I don't know if it's normal, but sometimes I have difficulties seeing my RPi when I can with my phone. I have to rescan several times before it appears.