I am trying to figure out a way to list the currently connected (and not just paired) bluetooth devices. I was wondering if there was an easy way to do this using pybluez. I need to trigger events based on the fact if a certain device is connected or not.

I am using a Raspberry Pi 3. Also, I understand that BLE devices periodically change their address, so, is there any way to check for a certain device repeatedly?

P.S. I am a beginner for both python and RPi.

  • Use bluetoothctlinfo AA:BB:CC:DD:EE:FF for getting device states. – Ephemeral Jan 15 at 9:52
  • The question answered here. – M. Rostami Jan 15 at 9:59
  • @M. Rostami That question only deals with devices that are nearby (not connected). Thanks for the effort, though. – Plyton Rexus Jan 15 at 10:21
  • @Ephemeral I did come across bluetoothctl and systemctl but don't really understand how to use either of them in Python. I know it can be done using a terminal, I know that much. – Plyton Rexus Jan 15 at 10:22
  • @PlytonRexus, You can use this python lib and follow this instructions. The project Development Status is Beta. You can find examples here – Ephemeral Jan 15 at 14:03

On the command line, you can request a list of connected BT devices with

$ hcitool con
> ACL 9C:65:B0:A0:1E:BD handle 11 state 1 lm MASTER AUTH ENCRYPT

Once you parse the MAC addresses from the output, you can check the device identity with

$ hcitool name "9C:65:B0:A0:1E:BD"
MY Mobile (GT-I9300I)

Even more info can be obtained with

$ hcitool info 9C:65:B0:A0:1E:BD
Requesting information ...
BD Address:  9C:65:B0:A0:1E:BD
OUI Company: Samsung Electronics Co.,Ltd (9C-65-B0)
Device Name: MY Mobile (GT-I9300I)
LMP Version: 4.0 (0x6) LMP Subversion: 0x7d3
Manufacturer: Qualcomm (29)
Features page 0: 0xff 0xfe 0x8f 0xfe 0xd8 0x3f 0x5b 0x87
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.