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

discoverAllServicesAndCharacteristics() doesn't always call callback. #50

Open
NAllred91 opened this issue Feb 15, 2018 · 4 comments
Open

Comments

@NAllred91
Copy link

When I make calls to peripheral.discoverAllServicesAndCharacteristics([callback]) the callback is not always called. It seems that if I put the call to discoverAllServicesAndCharacteristics in a setTimeout I can get the callback to be called more frequently, but the callback is still mostly never called.

@NAllred91
Copy link
Author

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

@NAllred91
Copy link
Author

Turns out, if the device is paired then the callback is never called. If the device is not paired then the callback is called.

@NAllred91
Copy link
Author

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)
            })
        }
    })
}

@ghost
Copy link

ghost commented Aug 19, 2018

@NAllred91 : does noble itself handle disconnects in the middle of discovering services?

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

1 participant