Tuesday, November 29, 2011

Scan for bluetooth devices using python

scan for bluetooth devices using a python script. the below script can be used for performing the same. remember , you will have to install pybluez module (it is available for both windows and linux). now for the script , here you go!

import bluetooth

print "performing inquiry..."

nearby_devices = bluetooth.discover_devices(lookup_names = True)

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

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

this will print the number of devices , address and name . this can be used as test script for a variety for reasons .

1 comment:

  1. Hi i'm trying to run the basic inquiry.py on my raspberry but i run in this issue.. I tried with 2 bluetooth dongle and they work if i do sudo hcitool scan

    This is the output i get when running inquiry.py

    pi@raspberrypi ~ $ sudo python inquiry.py
    performing inquiry...
    Traceback (most recent call last):
    File "inquiry.py", line 12, in
    nearby_devices = bluetooth.discover_devices(lookup_names = True)
    File "/usr/lib/python2.7/dist-packages/bluetooth/bluez.py", line 22, in discover_devices
    raise BluetoothError ("error communicating with local "
    bluetooth.btcommon.BluetoothError: error communicating with local bluetooth adapter