Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
蓝牙设备';对等机重置连接';尝试通过python进行配对时_Python_Bluetooth_Raspberry Pi_Rssi - Fatal编程技术网

蓝牙设备';对等机重置连接';尝试通过python进行配对时

蓝牙设备';对等机重置连接';尝试通过python进行配对时,python,bluetooth,raspberry-pi,rssi,Python,Bluetooth,Raspberry Pi,Rssi,我正在通过以下代码从我的计算机连接到Raspberry Pi import bluetooth MACaddr = 'F0:65:DD:6B:81:FD' #Mac address of Raspberry Pi used in test port = 1 print "Device found!\n Pairing with device." sock = bluetooth.BluetoothSocket (bluetooth.RFCOMM) sock.connect((MACaddr

我正在通过以下代码从我的计算机连接到Raspberry Pi

import bluetooth

MACaddr = 'F0:65:DD:6B:81:FD'
#Mac address of Raspberry Pi used in test
port = 1

print "Device found!\n Pairing with device."

sock = bluetooth.BluetoothSocket (bluetooth.RFCOMM)
sock.connect((MACaddr, port))
我的计划是让我的笔记本电脑连接到两个覆盆子Pis。然后,Pis将用我笔记本电脑的RSSI值计算我在两者之间的大致距离

当我运行“sudo hcitool rssi F0:65:DD:6B:81:FD” 大约30秒后,我将收到返回的RSSI值,但大约30秒后,python程序返回:

File "bt.py", line 12, in <module>
sock.connect((MACaddr, port))
File "<string>", line 5, in connect
bluetooth.btcommon.BluetoothError: (104, 'Connection reset by peer')
文件“bt.py”,第12行,在
sock.connect((MACaddr,端口))
文件“”,第5行,在connect中
bluetooth.btcommon.bluetooth错误:(104,“对等方重置连接”)

它似乎在“sock.connect((MACaddr,port))”时崩溃了,在执行之后什么都不做。我想您正在使用PyBluez。您确实需要说明版本。据我回忆,hcitool直接调用ioctl和驱动程序,而pybluez调用dbus接口——因此,如果没有正确运行和配置dbus,它就会挂起并最终放弃。我使用的版本有很多bug,最后我编写了自己的python模块来包装ioctl调用(它允许您访问bluez中未实现的更高级协议)因此,我建议您首先检查系统日志和dbus日志。此外,我不建议使用RSSI来估计距离,尤其是在如此低的信号水平下。有更精确的方法使用三角测量(但你必须四处移动才能得到一个定位)。但是,如果您想要一种避免ioctl和bluez的方法,那么在/var/lib/bluetooth/中有一个很好的小驱动程序数据库,您可以在运行hcitool命令后通过子进程命令填充和调用hcitool,从文件中获取该信息。