Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 715
Ufoguy Avatar asked Jan 08 '14 16:01

Ufoguy


2 Answers

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
like image 163
Kobi K Avatar answered Oct 31 '22 11:10

Kobi K


You can use PyBluez:

import bluetooth

nearby_devices = bluetooth.discover_devices()
like image 30
zero_dev Avatar answered Oct 31 '22 12:10

zero_dev