0

I want to discover Bluetooth devices without devices that already I have already paired. But my python script shows the Bluetooth device that are ON + the device sthat I have paired with. How I can filter just devices that are ON and ignore the paired devices from PC without deleting them.

This is my script

import bluetooth
def search():
    devices = bluetooth.discover_devices(duration=1, lookup_names = True)
    return devices

if __name__=="__main__":
    while True:
        results = search()
        if (results!=None):
            for addr, name in results:
                print ("{0}".format(name))
                print ("{0}".format(addr))
Anurag A S
  • 725
  • 10
  • 23

1 Answers1

0

I do not think you can do this via pybluez API which is not even under active development. If we look at the API you can set flush_cache to False to not the see previously discovered devices. But again it does show paired devices.

def discover_devices (duration=8, flush_cache=True, lookup_names=False,
                      lookup_class=False, device_id=-1, iac=IAC_GIAC):

But also below, I see that:

try:
    results = _bt.hci_inquiry (sock, duration=duration, flush_cache=True,
                               lookup_class=lookup_class, device_id=device_id,
                               iac=iac)

You might want to try setting this to a False and give it a shot.

I do not want to discover the paired devices is also seems not possible via D-BUS API. If we look at the adapter-api.txt there is a void SetDiscoveryFilter(dict filter) method, but it does not do what you want.

Another workaround is using DBUS API to get the info of if the device is discovered or not then make some list if it is not paired, then you will have a nice list of unpaired devices. If your domain is Linux, you might want to check where cache is kept.

Mr. Panda
  • 485
  • 3
  • 14