Node.js 蓝牙连接出现问题。覆盆子pi3和nodejs 7.4.0

Node.js 蓝牙连接出现问题。覆盆子pi3和nodejs 7.4.0,node.js,bluetooth,raspberry-pi,raspbian,Node.js,Bluetooth,Raspberry Pi,Raspbian,屁股每个人在他们的第一篇帖子里说“我是新的”,并试图找出一个复杂性 我想在Raspberry区域扫描并创建可用wifi网络列表,然后通过蓝牙将列表发送到手机 下一步-选择手机列表中的一个网络,输入所选网络的密码,然后通过蓝牙发送回Raspberry 我正在使用Raspberry pi3和板上蓝牙、Raspbian操作系统和nodejs v7.4.0 我选择使用wifi网络,它的效果非常好。有一件事-我应该用sudo运行npm run来获取所有网络,而不仅仅是当前网络 然后我尝试通过lib使用蓝牙

屁股每个人在他们的第一篇帖子里说“我是新的”,并试图找出一个复杂性

  • 我想在Raspberry区域扫描并创建可用wifi网络列表,然后通过蓝牙将列表发送到手机
  • 下一步-选择手机列表中的一个网络,输入所选网络的密码,然后通过蓝牙发送回Raspberry
  • 我正在使用Raspberry pi3和板上蓝牙、Raspbian操作系统和nodejs v7.4.0

    我选择使用wifi网络,它的效果非常好。有一件事-我应该用sudo运行npm run来获取所有网络,而不仅仅是当前网络

    然后我尝试通过lib使用蓝牙。 首先,我做了所有文档中的准备工作。
    var btSerial=new(需要('bluetooth-serial-port')).BluetoothSerialPort();
    
    btSerial.inquire()遇到了完全相同的问题。我的解决方案(可能适合也可能不适合您的需要)是事先通过
    bluetoothctl
    配对手机。(这已经是你为什么这个解决方案有点糟糕的原因:你不能在第二天来使用不同的电话/pi,当换成不同的pi:D时,事情就完全搞砸了) 哦,主脚本应该作为root运行,否则所有这些都无法工作

    1)配对您的设备

    $ bluetoothctl
    [bluetoothctl] agent on
    [bluetoothctl] discoverable on
    [bluetoothctl] pairable on
    [bluetoothctl] scan on
    
    (现在您在手机上打开蓝牙并搜索设备,在bluetoothctl中,您将看到显示的设备和mac)

    (手机将显示“yo this device want to pair”-对话框,bluetoothctl也希望您确认配对)

    现在,您可以随时通过蓝牙连接到pi,无论是否可以发现。(我正在使用)

    2)设备间的实际通话

    const rfcommProc = spawn(
        'rfcomm',
        ['watch', 'hci0', '1', 'node', `${__dirname}/myscript.js`]
    );
    
    所有本应与蓝牙配合使用的npm软件包都不适合我。一个也没有。所以最后我使用了
    rfcomm
    ,它能够在连接上启动程序。我让
    rfcomm
    运行
    节点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页面,了解如何立即接收和发送资料。(: 希望这能给你一些想法和/或帮助

    3)注意

    $ bluetoothctl
    [bluetoothctl] agent on
    [bluetoothctl] discoverable on
    [bluetoothctl] pairable on
    [bluetoothctl] scan on
    
    • 蓝牙服务启动得很晚。制作一个需要它的服务对我来说并不合适,但将它添加到
      rc.local
      似乎“太晚了”,以至于它在启动时运行并监听

      • 遇到了完全相同的问题。我的解决方案(可能适合也可能不适合您的需要)是事先通过
        bluetoothctl
        配对手机。(这已经是你为什么这个解决方案有点糟糕的原因:你不能在第二天来使用不同的电话/pi,当换成不同的pi:D时,事情就完全搞砸了) 哦,主脚本应该作为root运行,否则所有这些都无法工作

        1)配对您的设备

        $ bluetoothctl
        [bluetoothctl] agent on
        [bluetoothctl] discoverable on
        [bluetoothctl] pairable on
        [bluetoothctl] scan on
        
        (现在您在手机上打开蓝牙并搜索设备,在bluetoothctl中,您将看到显示的设备和mac)

        (手机将显示“yo this device want to pair”-对话框,bluetoothctl也希望您确认配对)

        现在,您可以随时通过蓝牙连接到pi,无论是否可以发现。(我正在使用)

        2)设备间的实际通话

        const rfcommProc = spawn(
            'rfcomm',
            ['watch', 'hci0', '1', 'node', `${__dirname}/myscript.js`]
        );
        
        所有本应与蓝牙配合使用的npm软件包都不适合我。一个也没有。所以最后我使用了
        rfcomm
        ,它能够在连接上启动程序。我让
        rfcomm
        运行
        节点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页面,了解如何立即接收和发送资料。(: 希望这能给你一些想法和/或帮助

        3)注意

        $ bluetoothctl
        [bluetoothctl] agent on
        [bluetoothctl] discoverable on
        [bluetoothctl] pairable on
        [bluetoothctl] scan on
        
        • 蓝牙服务启动得很晚。制作一个需要它的服务对我来说并不合适,但将它添加到
          rc.local
          似乎“太晚了”,以至于它在启动时运行并监听