与RPi建立成功的蓝牙连接 [英] Making a successful Bluetooth Connection to RPi
问题描述
我的PC上有一个RPi和一个普通的Debian,都使用Bluetooth Python模块进行通信.两者都有一些蓝牙USB加密狗.
我可以将pc用作服务器,将RPi用作客户端,此连接效果很好.但是,反之亦然,我无法做到这一点,我检查了rfcomm.conf
和main.conf
,但似乎都没问题.
还有其他陷阱吗?
I have a RPi and a normal Debian on my pc, both using the Bluetooth Python module to communicate. Both have some Bluetooth USB dongle in them.
I can use the pc as server and the RPi as client, this connection works very well. However I'm not able to do it vice versa, I checked my rfcomm.conf
and main.conf
, but both seem to be ok.
Any other pitfalls?
#Server.py
import bluetooth
server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = 1
server_sock.bind(("",port))
server_sock.listen(1)
client_sock,address = server_sock.accept()
print "Accepted connection from ",address
data = client_sock.recv(1024)
print "received [%s]" % data
client_sock.close()
server_sock.close()
#Client.py
import bluetooth
bd_addr = #myspecificmacaddress
port = 1
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((bd_addr, port))
sock.send("hello!!")
sock.close()
更准确地说:在RPi上运行Client.py
并在pc上运行Server.py
可以正常工作,反之亦然,显然是在纠正了MAC的情况下,只需说:bluetooth.btcommon.BluetoothError: (112, 'Host is down')
So to be more precise: Running Client.py
on RPi and Server.py
on pc works fine, doing vice versa, obviously with corrected MAC, simply says: bluetooth.btcommon.BluetoothError: (112, 'Host is down')
推荐答案
原来我的配置文件不太好. (它必须对配置文件进行某些操作)
Turned out that my config files weren't that well. (it must had to do something with config files)
/etc/bluetooth/main.conf
具有一个类部分. /var/lib/bluetooth/XX:XX:XX:XX:XX:XX/config
也有一个类部分.
/etc/bluetooth/main.conf
has a class section. /var/lib/bluetooth/XX:XX:XX:XX:XX:XX/config
has a class section, too.
我不知道为什么,我不知道实际情况或实际发生的事情,因为您无法在Internet上找到关于此的任何信息,但是将 both 都设置为0x400100
可以解决该问题.我不知道他们是否必须匹配,或者这是我发大财的特殊事情,但是它确实有效,我真的不想再次打破它.
I do not know why, I do not know how or what is actually happening, as you are not able to find anything about this on the internet, but setting both to 0x400100
fixed it. I don't know if they just have to match or if it's some special thing I came up by fortune, but it works and I dont really want to possibly break it again.
也许对此有更多了解的人愿意在这里改善我的答案.
Maybe someone with more knowledge about this is willing to improve my answer here.
这篇关于与RPi建立成功的蓝牙连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!