PyBluez connection problems

20 Views Asked by At

I'm a complete newbie to bluetooth technology. Now I'm trying to create a script that would connect to my phone and capture data from it. Ideally, I would like to try to catch the sound transmitted to my device, like a bluetooth headset.

Now my script hangs endlessly while trying to create a socket, what could be the problem?

import bluetooth

devices = bluetooth.discover_devices(lookup_names=True)
for addr, name in devices:
    if 'Yealink' in name:
        print(f"Найдено устройство: {name} с адресом {addr}")
        address = addr
        break

print("Connecting..")

port = 3
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.settimeout(10)
sock.connect((address, port))


print("Connected. Type something...")
while True:
    data = input()
    if not data:
        break
    sock.send(data)

sock.close()

bluetooth works fine on my pc.


pythonProject  uname -a
Linux 5.16.0-051600-generic #202201092355 SMP PREEMPT Mon Jan 10 00:21:11 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

My adapter is UB500.



PyBluez version:
Name: PyBluez
Version: 0.23
Summary: Bluetooth Python extension module
Home-page: http://pybluez.github.io/
Author: Albert Huang
Author-email: [email protected]
License: GPL
Location: /home/vladislav/.local/lib/python3.8/site-packages
Requires: 
Required-by: 
0

There are 0 best solutions below