How to access an bluetooth-agent with python script?

226 Views Asked by At

On a RPi4 with Debian I use

sudo bluetoothctl
  power on
  discoverable on
  pairable on
  agent NoInputNoOutput
  default-agent

to be able to pair e.g. my smartphone to this Rpi. These steps are also possible to trigger from an python script (e.g. with subprocess.run() ).

After that steps I can connect a profile like Audio streaming. In bluetoothctl it needs to

  1. confirm the passkey with typing yes and press enter
  2. confirm the "audio-request" in the agent with yes and press enter.

I would like to confirm the steps 1. and 2. with a python script. Like listening on the Bluetooth agent and as soon as it asks for confirmation, i would like to feedback yes. But I don't know how I can interact with that Bluetoothctl agent on python.

I already tried to open a subprocess

returnstring = subprocess.run(["bluetoothctl"], stdout = subprocess.PIPE, timeout = 5 )

in python with timeout (5s). My hope was, to finally get as STDOUT a string with the question about "... accepting profile: yes/no". But I just received an error and timeout.

Any proposals?

Thank you!

0

There are 0 best solutions below