Posts: 4
Joined: Thu Jan 10, 2019 6:45 pm

Programming bluetooth module of RPi 3 B

Thu Jan 10, 2019 6:57 pm

I'm trying to scan the invironment of the Pi for active bluetooth devices. I'd like to have MACs, names and signal strength.
Of course I can run

Code: Select all

in the shell and then use

Code: Select all

scan on
command but it is not the thing I'm looking for:
1) It is not able to see some devices for some reason (my phone for example).
2) It is not convenient to use within Python code (if even possible)

The documentation on the RPi website has no information upon embedded Bluetooth API (at least I wasn't able to find).

Some of the Python modules (pyblues, native sockets) are not well documented and almost no solution available on the web.

Is there any tutorials of good docs on the subject?

User avatar
Posts: 4542
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Programming bluetooth module of RPi 3 B

Fri Jan 11, 2019 12:09 am

1. bluetoothctl should have no problem scanning for your phone, assuming it's in 'discoverable' mode. If it's not, no software will help.

2. A module like pexpect makes it much easier to use bluetoothctl from within Python. Alternatively, everything I know about PyBluez came from the official documentation, so I can't help with tutorials. Perhaps someone here can help, meanwhile, search the internet. A very quick search turns up these, for example:
http://pages.iu.edu/~rwisman/c490/html/ ... etooth.htm
http://blog.kevindoran.co/bluetooth-pro ... -python-3/

Return to “Python”