Open NAllred91 opened 6 years ago
This seems to just be an issue when building with an electron app. I can't reproduce this on my desktop using Node 6.11.5
Turns out, if the device is paired then the callback is never called. If the device is not paired then the callback is called.
It looks like it might be because initially services
is an empty array. This code seems to work for now, but it doesn't handle disconnects in the middle of discovering services.
function discoverServices(peripheral, callback) {
peripheral.once('servicesDiscover', (services) => {
if(services.length === 0) {
console.warn('empty services!')
discoverServices(peripheral, callback)
}
else {
async.each(services, (service, callback) => {
service.discoverCharacteristics([], (err, characteristics) => {
if(err) callback(err)
else {
service.characteristics = characteristics
callback()
}
})
}, (err) => {
callback(err, services)
})
}
})
}
@NAllred91 : does noble itself handle disconnects in the middle of discovering services?
When I make calls to
peripheral.discoverAllServicesAndCharacteristics([callback])
the callback is not always called. It seems that if I put the call todiscoverAllServicesAndCharacteristics
in a setTimeout I can get the callback to be called more frequently, but the callback is still mostly never called.