Reputation: 11
So, what I'm trying to do is create a Python script which allows me to connect an android phone via Bluetooth with a Raspberry Pi. If I do this manually (writing the instructions in the command line) it works just fine, I can search, pair and connect any device in range.
However, if I do this via script, the message No agent is registered pops up when I try to activate the agent, meaning I won´t be able to pair any device, given this is the instrument which makes shure the confirmation code shown both in the Raspberri Pi and Android phone coincides.
The code I'm using looks somewhat like this.
import os
import sys
import time
os.system('sudo systemctl enable bluetooth')
os.system('sudo systemctl start bluetooth')
os.system('bluetoothctl discoverable on')
os.system('bluetoothctl agent on')
os.system('bluetoothctl default-agent')
os.system('bluetoothctl pairable on')
os.system('timeout 30 bluetoothctl scan on')
os.system('bluetoothctl pair XX:XX:XX:XX:XX:XX')
Any help or ideas will be much appreciated
Upvotes: 1
Views: 689
Reputation: 11
I made it work by using 'hcitool' instructions instead of 'bluetoothctl' and 'btnap' instead of BlueZ.
Upvotes: 0
Reputation: 7994
bluetoothctl
was not intended to be used in this way. To access BlueZ functionality from Python BlueZ provide a set of D-Bus APIs that are documented at:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc
They have Python examples of how to use those APIs at: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test
Upvotes: 2