In python I am trying to connect a device via bluetooth. I want to also send the the bluetooth passkey automatically. I tried one method using subprocess but I am getting an error.
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))
'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
语法)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.