Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gets stuck in the function discoverSomeServicesAndCharacteristicsAsync without any errors #305

Open
Matebo opened this issue Mar 20, 2023 · 1 comment

Comments

@Matebo
Copy link

Matebo commented Mar 20, 2023

Problem

After about 0 to 10 minutes of scanning it get stuck in the function discoverSomeServicesAndCharacteristicsAsync. Any suggestions?

Scanning code

const noble = require('@abandonware/noble/with-custom-binding')({extended: true});
 
 
noble.on('stateChange', async (state) => {
  console.log('stateChange received: '+state);
  if (state === 'poweredOn') {
    console.log('poweredOn received');
    noble.startScanningAsync([],true);
  }
});
 
noble.on('warning', async () => {
    console.log('warning');
});
 
noble.on('disconnect', async () => {
    console.log('disconnect');
});
 
noble.once('rssiUpdate', async () => {
    console.log('rssiUpdate');
});
 
noble.on('discover', async (peripheral) => {
  console.log('discovered: '+peripheral.address + ' rssi: '+peripheral.rssi);
  if (peripheral.address === 'xx:xx:xx:xx:xx:aa') {
    console.log('tag found')
    console.log("state: ", peripheral.state)
    printDetailsBattery(peripheral);
  }
});
 
async function printDetailsBattery(peripheral) {
  if (peripheral.state !== 'disconnected') {
    return;
  }
 
  //noble.reset();
  console.log("stopScanningAsync")
  await noble.stopScanningAsync()
  console.log("connectAsync")
  await peripheral.connectAsync();
    // 180f = battery service
    // 2a19 = battery level
  console.log("discoverSomeServicesAndCharacteristicsAsync")
  const {characteristics} = await peripheral.discoverSomeServicesAndCharacteristicsAsync(['180f'], ['2a19']);
  console.log("readAsync")
  const batteryLevel = (await characteristics[0].readAsync())[0];
  console.log(`battery level: ${peripheral.address}, ${batteryLevel}%`);
  console.log("disconnectAsync")
  await peripheral.disconnectAsync();
  console.log("startScanningAsync")
  await noble.startScanningAsync([],true);
}

Last output before getting stuck

discovered: xx:xx:xx:xx:xx:88 rssi: -85
discovered: xx:xx:xx:xx:xx:77 rssi: -90
discovered: xx:xx:xx:xx:xx:66 rssi: -72
discovered: xx:xx:xx:xx:xx:55 rssi: -72
discovered: xx:xx:xx:xx:xx:44 rssi: -62
discovered: xx:xx:xx:xx:xx:33 rssi: -97
discovered: xx:xx:xx:xx:xx:22 rssi: -76
discovered: xx:xx:xx:xx:xx:11 rssi: -98
discovered: xx:xx:xx:xx:xx:aa rssi: -59
tag found
state:  disconnected
stopScanningAsync
discovered: xx:xx:xx:xx:xx:ab rssi: -93
connectAsync
discoverSomeServicesAndCharacteristicsAsync
@lamroger
Copy link

lamroger commented Dec 18, 2023

I had a similar issue but it wasn't finding my characteristic at all and worked around it by enumerating all of them and filtering after

  const characteristics = await services[0].discoverCharacteristicsAsync();
  const tempCharacteristic = characteristics.find(c => c.uuid === TEMP_CHARACTERISTIC_UUID);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants