0

I'm new to python and with bluetoothctl and I need to automate the bluetoothcl scan on process in python so that I just need to open the python file and start scanning right away.

I've been doing a lot of research but the code I've been finding doesn't work. I can scan through the terminal using bluetooth but I really needed an automation in python3 to scan all the bluetooth devices around me with my Rasp.

Thanks for help.

2
  • 2
    Well first of all, show us your attempts and describe in more details your ultimate goal and the issues you've encountered. Saying the code doesn't work is not an accurate description of your problem. Surely, you have error messages and symptoms to report ?
    – Kate
    Commented Aug 19, 2021 at 17:47
  • My understanding is that bluetoothctl was not intended to be used in that way. It is expected that the BlueZ D-Bus API is used for such Bluetooth scripting. More information at: stackoverflow.com/a/65937350/7721752
    – ukBaz
    Commented Aug 20, 2021 at 5:58

1 Answer 1

-1

Regardless if you need sudo, this line does the work for me:

import subprocess
subprocess.Popen(["sudo", "bluetoothctl", "scan", "on"], stdout=subprocess.PIPE, stdin=subprocess.PIPE)

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.