I'm trying to make a simple bluetooth service on Python using PyBluez and looks like it works, but I can't find that service with neither my phone, nor with PyBluez itself. I'm able to discovery my phone bluetooth when I do search with PyBluez, but not the server created with PyBluez. What's wrong with the code bellow?
import bluetooth
server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = 0 # automatically choose port
server_sock.bind(("",port))
server_sock.listen(1)
uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848"
bluetooth.advertise_service( server_sock, "FooBar Service", uuid )
client_sock,address = server_sock.accept()
print "Accepted connection from ",address
data = client_sock.recv(1024)
print "received [%s]" % data
client_sock.close()
server_sock.close()
I'm enabling service visibility with hciconfig hci0 piscan
, so my phone is able to find a bluetooth device with name of my PC, but not the service I've created (I mean FooBar Service
).
Also I can't find my service using sdptool browse
command.
Do I misunderstand something? How to connect to the service I've created?
update
Here is the below mentioned code result executed on my Windows 7 PC with D-Link Bluetooth adapter.
update
Finally it worked when I run client from another computer. It doesn't work locally, but why I can't discover this service from any device? Is there anything special I should do to make it behave like a normal Bluetooth service?