蓝牙连接问题。树莓派 3 和 nodejs 7.4.0
Issue with Bluetooth connection. Raspberry pi3 and nodejs 7.4.0
让每个人都在他们的第一篇帖子中说 "I'm new one" 并试图找出一个复杂性。
- 我想扫描并创建 Raspberry 区域的可用 wifi 网络列表,然后通过蓝牙将列表发送到 phone。
- 下一步 - select phone 列表中的网络之一,输入 selected 网络的密码并通过蓝牙发送回 Raspberry
我正在使用带蓝牙的 Raspberry pi3,Raspbian OS 和 nodejs v7.4.0
我选择 wifi-control 使用 wifi 网络,效果很好。一件事-我应该 运行 npm 运行 和 sudo 来获取所有网络,而不仅仅是当前网络;
然后我尝试通过 bluetooth-serial-port 库使用蓝牙。
首先,我做了所有写在文档中的准备工作。
var btSerial = new (require('bluetooth-serial-port')).BluetoothSerialPort();
btSerial.inquire();
它什么也不做。至少我没有看到任何效果 - 我的 phone 没有 "see" Raspberry 在可用的蓝牙设备列表中;
我以为我的 Raspberry 蓝牙有问题,但后来我 运行
bluetoothctl -> 打开电源 -> 可发现
Raspberry 出现在 phone。
我应该如何 "turn on" 蓝牙控制并将我的 Raspberry 添加到可用蓝牙设备列表?
和平!
遇到完全相同的问题。我的解决方案(可能适合也可能不适合您的需求)是预先通过 bluetoothctl
配对 phone。 (这已经是你为什么这个解决方案有点糟糕了:你不能在第二天来使用不同的 phone/pi,当改变到不同的 pi 时,东西完全搞砸了:D)
哦,主脚本应该 运行 作为 root,否则所有这些都不会工作。
1) 正在配对您的设备
$ bluetoothctl
[bluetoothctl] agent on
[bluetoothctl] discoverable on
[bluetoothctl] pairable on
[bluetoothctl] scan on
(现在您在 phone 上打开蓝牙并搜索设备,在 bluetoothctl 中您应该会看到您的设备并显示 mac)
[bluetoothctl] pair XX:XX...(MAC of your phone)
(phone 将显示 "yo this device wants to pair"-对话框并且 bluetoothctl 也希望您确认配对)
现在您可以随时通过蓝牙连接到 pi,无论它是否可被发现。 (我正在使用 Serial Bluetooth Terminal)
2) 设备之间的实际对话
NONE 应该与蓝牙一起工作的 npm 包对我有用。一个都没有。所以最后我使用了 rfcomm
并且它能够在连接时启动程序。与 serialport 一起,我让 rfcomm
运行 node myscript.js
建立实际的串行连接,如下所示:
2.1) rfcomm
等待连接
const rfcommProc = spawn(
'rfcomm',
['watch', 'hci0', '1', 'node', `${__dirname}/myscript.js`]
);
2.2)myscript.js
开放端口
const port = new SerialPort('/dev/rfcomm0', spError => {
if (spError) {
process.send(spError);
}
})
立即查看 npmjs-page 如何接收和发送内容。(:
希望这能给你一些想法 and/or 帮助。
3) 注
- 蓝牙服务启动很晚。制作需要它的服务对我来说没有用,但将它添加到
rc.local
似乎是 "late enough" 让它 运行 宁并在启动时收听。
让每个人都在他们的第一篇帖子中说 "I'm new one" 并试图找出一个复杂性。
- 我想扫描并创建 Raspberry 区域的可用 wifi 网络列表,然后通过蓝牙将列表发送到 phone。
- 下一步 - select phone 列表中的网络之一,输入 selected 网络的密码并通过蓝牙发送回 Raspberry
我正在使用带蓝牙的 Raspberry pi3,Raspbian OS 和 nodejs v7.4.0
我选择 wifi-control 使用 wifi 网络,效果很好。一件事-我应该 运行 npm 运行 和 sudo 来获取所有网络,而不仅仅是当前网络;
然后我尝试通过 bluetooth-serial-port 库使用蓝牙。 首先,我做了所有写在文档中的准备工作。
var btSerial = new (require('bluetooth-serial-port')).BluetoothSerialPort();
btSerial.inquire();
它什么也不做。至少我没有看到任何效果 - 我的 phone 没有 "see" Raspberry 在可用的蓝牙设备列表中;
我以为我的 Raspberry 蓝牙有问题,但后来我 运行
bluetoothctl -> 打开电源 -> 可发现
Raspberry 出现在 phone。
我应该如何 "turn on" 蓝牙控制并将我的 Raspberry 添加到可用蓝牙设备列表?
和平!
遇到完全相同的问题。我的解决方案(可能适合也可能不适合您的需求)是预先通过 bluetoothctl
配对 phone。 (这已经是你为什么这个解决方案有点糟糕了:你不能在第二天来使用不同的 phone/pi,当改变到不同的 pi 时,东西完全搞砸了:D)
哦,主脚本应该 运行 作为 root,否则所有这些都不会工作。
1) 正在配对您的设备
$ bluetoothctl
[bluetoothctl] agent on
[bluetoothctl] discoverable on
[bluetoothctl] pairable on
[bluetoothctl] scan on
(现在您在 phone 上打开蓝牙并搜索设备,在 bluetoothctl 中您应该会看到您的设备并显示 mac)
[bluetoothctl] pair XX:XX...(MAC of your phone)
(phone 将显示 "yo this device wants to pair"-对话框并且 bluetoothctl 也希望您确认配对)
现在您可以随时通过蓝牙连接到 pi,无论它是否可被发现。 (我正在使用 Serial Bluetooth Terminal)
2) 设备之间的实际对话
NONE 应该与蓝牙一起工作的 npm 包对我有用。一个都没有。所以最后我使用了 rfcomm
并且它能够在连接时启动程序。与 serialport 一起,我让 rfcomm
运行 node myscript.js
建立实际的串行连接,如下所示:
2.1) rfcomm
等待连接
const rfcommProc = spawn(
'rfcomm',
['watch', 'hci0', '1', 'node', `${__dirname}/myscript.js`]
);
2.2)myscript.js
开放端口
const port = new SerialPort('/dev/rfcomm0', spError => {
if (spError) {
process.send(spError);
}
})
立即查看 npmjs-page 如何接收和发送内容。(: 希望这能给你一些想法 and/or 帮助。
3) 注
- 蓝牙服务启动很晚。制作需要它的服务对我来说没有用,但将它添加到
rc.local
似乎是 "late enough" 让它 运行 宁并在启动时收听。