I am trying to connect to a bluetooth device with my Pi 4 via Bluetooth. Upon boot, I want the Pi 4 to automatically turn on its bluetooth and select the device with the strongest signal and then request for pairing. Assume that the devices shown below are all Pi Zero W. After pairing, the pi 4 should send a text file to the Pi Zero W with the strongest signal. Can anyone give sort of direction I could try to achieve this ? Do let me know if I need to do anything on the Pi Zero W other than making its bluetooth discoverable. Thanks in advance.

enter image description here

1 Answer 1


You probably need to break this into small parts and solve them individually before bringing it back together for the overall solution.

File transfer on Bluetooth is typically done with with the Generic Object Exchange Profile (GOEP). There is some more information about this at:

Raspberry pi 4 bluetooth file transfer rate

Pairing is normally a one-off provisioning/security step the first time two devices want to connect. After this is done the first time, subsequent connections can happen without pairing again. I suspect you don't want to randomly pair with devices as that seems like a security issue.

To do the nearby devices discovery and look at the RSSI value, you might be able to adapt the code in:

Rpi Zero W - How to automatically accept bluetooth pairing and log mac and info request?

The above code looks at the Connected property whereas you are interested in the RSSI property. The full list of properties are available in the BlueZ documentation for the Device API.

  • Noted thanks. I'll approach it part by part. Using the bluetoothctl command, i paired the pi with another pi. It was unsuccessful with the following error message: [bluetooth]# connect C4:93:D9:8C:4B:C7 Attempting to connect to C4:93:D9:8C:4B:C7 Failed to connect: org.bluez.Error.Failed
    – snow
    Aug 29, 2020 at 18:58
  • addon to above post, because I failed to connect i ca
    – snow
    Aug 29, 2020 at 19:01
  • Bit tricky to answer with the information you have shared. You might want to follow the instructions at: bluedot.readthedocs.io/en/latest/pairpipi.html. Generally there needs to be a service at both ends of the Bluetooth link for connections to work. As an experiment, you might want to start a serial port server on one github.com/martinohanlon/BlueDot/blob/master/examples/…. Then start the client on the other github.com/martinohanlon/BlueDot/blob/master/examples/…
    – ukBaz
    Aug 29, 2020 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.