How to find visible bluetooth devices in Python? [duplicate]
Asked Answered
A

2

9

I need to find the list of visible Bluetooth devices with their respective details in the range of my Bluetooth modem. I only need to do Bluetooth 2.0 and below. I don't need to do Bluetooth 4.0.

Like you do on an Android phones using "Search for devices".

I'm sorry I can't give any code I tried because I don't know how to do Bluetooth with python.

Averill answered 8/1, 2014 at 16:4 Comment(2)
What platform are you wanting to do this on? Android? Linux? Something else?Gisele
@CharlieKilian I'd like to be able do it on both Linux and Windows.Averill
G
18

PyBluez:

from bluetooth import *

print "performing inquiry..."

nearby_devices = discover_devices(lookup_names = True)

print "found %d devices" % len(nearby_devices)

for name, addr in nearby_devices:
     print " %s - %s" % (addr, name)

See also Programming Bluetooth using Python

The important thing is you can use lookup_names = True

from bluez Docs:

if lookup_names is False, returns a list of bluetooth addresses.
if lookup_names is True, returns a list of (address, name) tuples
Gq answered 8/1, 2014 at 16:10 Comment(2)
prebuilt for windows: lfd.uci.edu/~gohlke/pythonlibs/#pybluezFabrice
PyBluez seems to be deprecated, it is not possible to install it anymore in Python 3.10 on WindowsAldershot
L
3

You can use PyBluez:

import bluetooth

nearby_devices = bluetooth.discover_devices()
Ladin answered 8/1, 2014 at 16:9 Comment(1)
Can you post example of the output it gives?Averill

© 2022 - 2024 — McMap. All rights reserved.