Listening for connections on port: 0
Traceback (most recent call last):
File "server.py", line 29, in <module>
runServer()
File "server.py", line 19, in runServer
profiles = [ bluetooth.SERIAL_PORT_PROFILE ]
File "/usr/lib/python2.7/dist-packages/bluetooth/bluez.py", line 176, in advertise_service
raise BluetoothError (str (e))
bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')
This is the Error that I am getting when I run the following Script on Raspberry Pi 3 Model B.
import bluetooth
name="bt_server"
target_name="siggen"
uuid="222705e1-e1e6-47f5-aa92-1c5ae849f3f1"
def runServer():
serverSocket=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port=bluetooth.PORT_ANY
serverSocket.bind(("",port))
print "Listening for connections on port: ", port
serverSocket.listen(1)
port=serverSocket.getsockname()[1]
#the missing piece
bluetooth.advertise_service( serverSocket, "SampleServer",
service_id = uuid,
service_classes = [ uuid, bluetooth.SERIAL_PORT_CLASS ],
profiles = [ bluetooth.SERIAL_PORT_PROFILE ]
)
inputSocket, address=serverSocket.accept()
print "Got connection with" , address
data=inputSocket.recv("1024")
print "received [%s] \n " % data
inputSocket.close()
serverSocket.close()
runServer()
I have bluez version 5.37. I have followed these links (link1) and (link2). They don't seem to solve the problem.
I can connect my android to raspberry pi using following terminal commands
sdptool add sp
It does not give any response.
sudo rfcomm listen hci0&
The device is connected (using blueterm app)
cat /dev/rfcomm0
This port is used to receive the data
Also, the following script works
import bluetooth
server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = 1
server_sock.bind(("",port))
server_sock.listen(1)
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()
Hence the bluetooth is totally functional. The only problem that I have is of profiles. I can't figure out what the problem is. Any sort of help is appreciated.
Thanks in advance for your help!