我找到了另一种可能的解决方案。我通过挖掘某人的git hub存储库发现了这一点。这使用内置的python3套接字模块。
先决条件:
- 您在地址<适配器地址>上有一个正常工作的适配器。
- 您的目标蓝牙设备位于<设备地址>。
- 设备已固定。
也就是说,可以使用rfcomm。
$python3
>>> import socket
>>> sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
>>> adapter = '00:11:22:33:44:55' #<adapter address>
>>> device = '55:44:33:22:11:00' #<device address>
>>> sock.bind((adapter, 1))
>>> sock.connect((device, 1))
## If not pinned it will ask you. You can use/adapt the bluez simple-agent for headless pinning
>>> sock.send(b'hello\n')
>>> sock.recv(100)
>>> sock.close()