5

I've been trying to get a simple python bluetooth example running on my lenovo y50-70 laptop running ubuntu 18. But while doing this i noticed that the Pybluez library is unable to find any devices, while using the bluetoothctl tool can.

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')))

Running the code above gives as an output: found 0 devices. While running bluetoothctl gives me the following output:

[NEW] Controller 40:B8:9A:44:E0:46 daan-Lenovo-Y50-70 [default]
Agent registered
[bluetooth]# scan on
Discovery started
[CHG] Controller 40:B8:9A:44:E0:46 Discovering: yes
[NEW] Device 30:AE:A4:37:A2:4A 30-AE-A4-37-A2-4A
[NEW] Device D0:D2:B0:91:1C:C5 D0-D2-B0-91-1C-C5
[NEW] Device 70:73:CB:DF:1B:08 70-73-CB-DF-1B-08
[NEW] Device 51:80:89:6F:6E:B6 51-80-89-6F-6E-B6
[bluetooth]#

I have tried running my python script as root, and my current pybluez version is 0.22. I hope anyone knows how to resolve this issue.

Darth Coder
  • 312
  • 2
  • 11

1 Answers1

0

My guess is that you're running into a similar issue to How to setup the enviroment that bluepy can scan without sudo?

The answer that worked for me in a similar situation is this one: https://stackoverflow.com/a/59798285/15546755

John
  • 46
  • 2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34568717) – Alez Jun 23 '23 at 12:47