树莓派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的输出见下图:
scan on卡住的状态见下图:
当前使用的BlueZ版本为5.50。
内容的提问来源于stack exchange,提问作者Mr. Panda
相关产品推荐
相关产品推荐

