【问题标题】:Python Bluetooth Sending PasskeyPython蓝牙发送密钥
【发布时间】:2018-02-09 15:47:09
【问题描述】:

在 python 中,我试图通过蓝牙连接设备。我还想自动发送蓝牙密码。我尝试了一种使用 subprocess 的方法,但出现错误。

代码

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.

【问题讨论】:

    标签: python bluetooth subprocess


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-23
      • 1970-01-01
      • 2014-06-11
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      • 2012-07-15
      相关资源
      最近更新 更多