You need to enable JavaScript to run this app. 树莓派4使用noble.js进行BLE扫描二次运行仅发现少量设备咨询
优惠活动
大模型
产品
解决方案
定价
更多

树莓派4使用noble.js进行BLE扫描二次运行仅发现少量设备咨询

我在树莓派4(Raspberry Pi 4)上运行noble官方示例代码,首次运行时功能正常,可扫描到大量设备;但重新运行后扫描功能异常,仅能发现少量设备:

noble.on('stateChange', function(state) {
  if (state === 'poweredOn') {
    noble.startScanning();
  } else {
    noble.stopScanning();
  }
});

noble.on('discover', function(peripheral) {
  console.log('peripheral discovered (' + peripheral.id +
              ' with address <' + peripheral.address +  ', ' + peripheral.addressType + '>,' +
              ' connectable ' + peripheral.connectable + ',' +
              ' RSSI ' + peripheral.rssi + ':');
  console.log('\thello my local name is:');
  console.log('\t\t' + peripheral.advertisement.localName);
  console.log('\tcan I interest you in any of the following advertised services:');
  console.log('\t\t' + JSON.stringify(peripheral.advertisement.serviceUuids));

  var serviceData = peripheral.advertisement.serviceData;
  if (serviceData && serviceData.length) {
    console.log('\there is my service data:');
    for (var i in serviceData) {
      console.log('\t\t' + JSON.stringify(serviceData[i].uuid) + ': ' + JSON.stringify(serviceData[i].data.toString('hex')));
    }
  }
  if (peripheral.advertisement.manufacturerData) {
    console.log('\there is my manufacturer data:');
    console.log('\t\t' + JSON.stringify(peripheral.advertisement.manufacturerData.toString('hex')));
  }
  if (peripheral.advertisement.txPowerLevel !== undefined) {
    console.log('\tmy TX power level is:');
    console.log('\t\t' + peripheral.advertisement.txPowerLevel);
  }

  console.log();
});

重启设备后该问题会消失。通过bluetoothctl执行scan on扫描完全无异常,可随意启停扫描,因此推测该问题与noble.js相关。

扫描停止时sudo btmon的输出见下图:
sudo btmon输出

scan on卡住的状态见下图:
scan on卡住截图

当前使用的BlueZ版本为5.50。


内容的提问来源于stack exchange,提问作者Mr. Panda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.21 12:09:00