I am working on a project to communicate between a raspberry pi & a series of Arduinos, using the HC-05 bluetooth modules, over a bluetooth connection. I am able to pair the arduinos using bluetoothctl and the communicating using python scripts, but I would like to include the pairing process in my scripts as well but I have not found a solution that includes the bluetooth pairing pin in the scripts.
What I've tried:
- The PyBluez library, but it is incapable of pairing.
- Subprocess, but I can't respond to the pin request (code below), but this results in an error of too many arguments (for bluetoothctl).
import subprocess, shlex
addr = "00:14:03:06:12:84"
pinCode = "1234"
args = ["bluetoothctl", f"pair {addr}", pinCode]
args = shlex(args)
subprocess.Popen(args)
- I also tried using the bluetoothctl wrapper, but there's is no pin option here either.
Is pairing via python possible?