bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')

报错:
bluetooth.btcommon.BluetoothError: (2, ‘No such file or directory’)
or
Failed to connect to SDP server on FF:FF:FF:00:00:00: No such file or directory

sudo vim /lib/systemd/system/bluetooth.service
修改 ExecStart=/usr/lib/bluez5/bluetooth/bluetoothd -E -C
sudo sdptool add SP
sudo systemctl daemon-reload
sudo systemctl restart bluetooth
sudo sdptool browse local

最后执行成功输出类是下面的结果:

Browsing FF:FF:FF:00:00:00 ...
Service RecHandle: 0x10000
Service Class ID List:
  "PnP Information" (0x1200)
Profile Descriptor List:
  "PnP Information" (0x1200)
    Version: 0x0103

Browsing FF:FF:FF:00:00:00 ...
Service Search failed: Invalid argument
Service Name: Generic Access Profile
Service Provider: BlueZ
Service RecHandle: 0x10001
Service Class ID List:
  "Generic Access" (0x1800)
Protocol Descriptor List:
  "L2CAP" (0x0100)
    PSM: 31
  "ATT" (0x0007)
    uint16: 0x0001
    uint16: 0x0005

Service Name: Generic Attribute Profile
Service Provider: BlueZ
Service RecHandle: 0x10002
Service Class ID List:
  "Generic Attribute" (0x1801)
Protocol Descriptor List:
  "L2CAP" (0x0100)
    PSM: 31
  "ATT" (0x0007)
    uint16: 0x0006
    uint16: 0x0009

Service Name: AVRCP CT
Service RecHandle: 0x10003
Service Class ID List:
  "AV Remote" (0x110e)
  "AV Remote Controller" (0x110f)
Protocol Descriptor List:
  "L2CAP" (0x0100)
    PSM: 23
  "AVCTP" (0x0017)
    uint16: 0x0103
Profile Descriptor List:
  "AV Remote" (0x110e)
    Version: 0x0106
...........

pybluez示例程序:

from bluetooth import *

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

port = server_sock.getsockname()[1]

# uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"
uuid = "00001101-0000-1000-8000-00805f9b34fb"

advertise_service( server_sock, "HAServer",
                   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)

while True:

    try:
        req = client_sock.recv(1024)
        if len(req) == 0:
            break
        data = req.decode()
        print("received [%s]" % data)
        print("sending [%s]" % data)
        client_sock.send(data)

    except IOError:
        pass

    except KeyboardInterrupt:

        print("disconnected")

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

        break

参考:
sdptool is broken in Bluez 5
解决android - Communicating via Bluetooth serial with Python

猜你喜欢

转载自blog.csdn.net/M_N_N/article/details/81302087