蓝牙加密狗连接被拒绝。

har*_*ash 5 hardware debian bluetooth

我有一个蓝牙加密狗(大约 2 美元),我想从中将串行数据发送到我的 android 手机。

我已经安装:

sudo apt-get install bluetooth bluez-utils blueman
Run Code Online (Sandbox Code Playgroud)

在扫描时,我找到了我的 android 设备(我猜这意味着加密狗正在工作)

hcitool scan
Run Code Online (Sandbox Code Playgroud)

之后我运行了这个:

sudo bluez-simple-agent hci0 xx:xx:xx:xx:xx:xx
Run Code Online (Sandbox Code Playgroud)

我编辑了这个文件: /etc/bluetooth/rfcomm.conf

对此:

rfcomm1 {
    bind yes;
    device xx:xx:xx:xx:xx:xx;
    channel 1;
    comment "Connection to Bluetooth serial module";
}
Run Code Online (Sandbox Code Playgroud)

但在跑步时

sudo rfcomm connect 1, 我得到 ' Can't connect RFCOMM socket: Connection refused'

问题是什么 ?

Vin*_*ard 0

问题是,尽管在您这边创建并绑定了套接字,但它无法成功调用 connect()。(来自bluez-X-Y.Z/tools/rfcomm.c来源)。connect() 调用失败(即返回值<0)可能由多种原因引起。

我想您真正的问题是“我怎样才能成功连接?”

要解决此问题,您必须首先绝对确定另一台计算机上有侦听套接字。我建议您使用在计算机上运行的另一个 bluez 堆栈来完成此操作。

在另一台机器上运行:

rfcomm listen 0           # listens on channel 1 by default
Run Code Online (Sandbox Code Playgroud)

并在测试机上运行:

rfcomm connect 0 00:11:22:33:44:55 1
Run Code Online (Sandbox Code Playgroud)

预期的行为没有错误。

然后你可以使用这个机制来连接套接字和登录,传输文件等......但这超出了你的问题。