PyBluez 'bad bluetooth address'

149 Views Asked by At

I am running Windows 11 and ideally I would like to 'talk' with my PS5 controller via the internal bluetooth of my laptop using python.
I was going to run this sample code for PyBluez, but I get the error message 'bad bluetooth address'.

from bluetooth import *

server_sock=BluetoothSocket()
server_sock.bind(("",PORT_ANY))
server_sock.listen(1)

port = server_sock.getsockname()[1]

uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"

advertise_service( server_sock, "SampleServer",
                   service_id = uuid,
                   service_classes = [ uuid, SERIAL_PORT_CLASS ],
                   profiles = [ SERIAL_PORT_PROFILE ], 
#                   protocols = [ OBEX_UUID ] 
                    )
                   
print("Waiting for connection on RFCOMM channel %d" % port)

client_sock, client_info = server_sock.accept()
print("Accepted connection from ", client_info)

try:
    while True:
        data = client_sock.recv(1024)
        if len(data) == 0: break
        print("received [%s]" % data)
except IOError as e:
    print(e)

print("disconnected")

client_sock.close()
server_sock.close()
print("all done")

Since PyBluez has a very suboptimal documentation I can't figure out a solution.

0

There are 0 best solutions below