2

I would like to make a bluetooth communication using python3 (pyBluez0.23 module)

I found on internet some tutorials which use the Pybluez library but this doesn't work for me. Find below the code for the server part :

import bluetooth

def setupServer():
    server_socket=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
    print("Socket Created.")
    port = 0
    server_socket.bind("",port)
    server_socket.listen(1)
    print("Socket bind complete")

    uuid = "xxx-xxx-xxxx-xxxx"
        
    bluetooth.advertise_service(server_sock, "Wifi config",
                      service_id=uuid,
                      service_classes=[uuid, bluetooth.SERIAL_PORT_CLASS],
                      profiles=[bluetooth.SERIAL_PORT_PROFILE])
        
    client_sock, client_info = server_sock.accept()
        
    self.handle_client(client_sock)
        
    client_sock.close()
    server_sock.close()

This is the output :

<bluetooth.msbt.BluetoothSocket object at 0x000002736C4BB610>
    bluetooth socket created.
    Traceback (most recent call last):
      File "ROS.py", line 99, in <module>
        main()
      File "ROS.py", line 96, in main
        BluetoothServerNode().start()
      File "ROS.py", line 67, in start
        server_sock.bind(("", blt.PORT_ANY))
      File "c:\opt\ros\noetic\x64\lib\site-packages\bluetooth\msbt.py", line 84, in bind
        bt.bind (self._sockfd, addr, port)
    OSError: A
siya
  • 43
  • 8
  • You don't appear to have put the address of the Bluetooth adapter on your PC in the bind statement. More information at: http://blog.kevindoran.co/bluetooth-programming-with-python-3/ – ukBaz Oct 12 '20 at 11:16
  • thanks for your response .i have also tried with that but got same error. – siya Oct 12 '20 at 12:55

0 Answers0