简体   繁体   English

Python蓝牙发送密码

[英]Python Bluetooth Sending Passkey

In python I am trying to connect a device via bluetooth. 在python中,我试图通过蓝牙连接设备。 I want to also send the the bluetooth passkey automatically. 我也想自动发送蓝牙密码。 I tried one method using subprocess but I am getting an error. 我尝试了使用子流程的一种方法,但出现错误。

Code

import subprocess

from bluetooth import *

print "performing inquiry..."

nearby_devices = discover_devices(lookup_names = True)

print "found %d devices" % len(nearby_devices)

for name, addr in nearby_devices:
 print " %s - %s" % (addr, name)


# kill any "bluetooth-agent" process that is already running
subprocess.call("kill -9 `pidof bluetooth-agent`",shell=True)

# Start a new "bluetooth-agent" process where XXXX is the passkey
status = subprocess.call("bluetooth-agent 9999 &",shell=True)

# Now, connect in the same way as always with PyBlueZ
# Create the client socket
client_socket=BluetoothSocket( RFCOMM )

client_socket.connect(("08:3D:88:1D:61:41", 3))

Error 错误

'kill' is not recognized as an internal or external command,
operable program or batch file.
'bluetooth-agent' is not recognized as an internal or external command,
operable program or batch file.

进行调用,处理类似的进程还有其他问题,但是最明显的也是导致失败的一个原因是您正在运行Windows版本的python(执行显然发生在cmd.exe )并尝试执行U *类似X的命令(并使用类似sh语法)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM