0

PyBluez's first and most basic example is "examples/simple/inquiry.py", which is described as "Detecting nearby Bluetooth devices". This is exactly what I'd like to do - detect and list nearby Bluetooth devices.

However when I run the example code:

import bluetooth

print("performing inquiry...")

nearby_devices = bluetooth.discover_devices(
        duration=8, lookup_names=True, flush_cache=True, lookup_class=False)

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

for addr, name in nearby_devices:
    try:
        print("  %s - %s" % (addr, name))
    except UnicodeEncodeError:
        print("  %s - %s" % (addr, name.encode('utf-8', 'replace')))

I notice that

  1. My phone's Bluetooth network is not detected even though the phone is about 4cm from the laptop which is running this script.
  2. The 4 Bluetooth devices listed are the 4 which are known/paired with my OS, even though none of them are within 10 miles of me at the moment.

So, I'm wondering why it's doing this and how to make it actually scan/list nearby devices?

I'm on Windows 7 and Python 3.5

Hack-R
  • 22,422
  • 14
  • 75
  • 131
  • Checked on GitHub, I assume **wrong** Description for the given Example code. The Linux `inquiry` Example code is much more extensive. – stovfl Jun 14 '17 at 15:50
  • I tried it on a Linux computer last night and it seemed to work closer to as expected. It detected the Bluetooth of my Windows laptop (tho not my phone). So it didn't have the same problem. I'm thinking that it's a Windows-specific problem the author may not be aware of since it looks like they mostly develop for Linux. Still, I wonder if there's a workaround for Windows. – Hack-R Jun 14 '17 at 17:21
  • Which one have you tried? Only the `asynchronous-inquiry.py` one **has** a Note **Linux only**. – stovfl Jun 14 '17 at 17:52
  • @stovfl Just `inquiry.py`, it's supposed to be Windows and Linux (that's the whole inquiry.py file within the question, just those few lines). – Hack-R Jun 14 '17 at 18:17

0 Answers0