Reputation: 11
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.
Upvotes: 0
Views: 425
Reputation: 9679
There are other problems with making the calls, dealing with processes like this, but the most obvious and the one causing the failure is that you are running windows version of python (the execution apparently happens with cmd.exe
) and try to execute U*X-like commands (and use sh
like syntax).
Upvotes: 0