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

No way to stop a BridgeFinder scan #31

Open
ahamel opened this issue Aug 20, 2018 · 3 comments
Open

No way to stop a BridgeFinder scan #31

ahamel opened this issue Aug 20, 2018 · 3 comments

Comments

@ahamel
Copy link

ahamel commented Aug 20, 2018

I can't seem to find a way to actually stop the scanner during the BridgeFinder flow. For example if you wanted to stop the scan with some timeout etc... I don't see any public API on the BridgeFinder class.

@NilsLattek
Copy link
Collaborator

Right now there are two ways implemented to scan for bridges: SSDPScanner which searches inside the local network and NUPNPScanner which makes a REST call to the Hue-cloud to receive the devices.
The first solution uses a scan timeout of 5 seconds:


and the second method is a standard HTTP request with the standard timeout of 60 seconds
This is just for finding the bridge IP after that it also needs to call each IP to validate that it is a valid bridge which is done with a REST call again:
let request = NSMutableURLRequest(url: url)
which also uses the default timeout. This call is done for each IP it can find during the first step.
I guess it would make sense to reduce the HTTP-timeouts a litte bit to 10-15seconds or something like that.
So right now it is not scanning forever.

Adding a stop() method is also an option and it is already implemented in the first scanner:

and supported in the scanner interface.
The remaining work would be to also cancel the request in the NUPNPScanner scanner and for the validator requests.

@ahamel
Copy link
Author

ahamel commented Aug 21, 2018

Thanks for the detailed update. Yeah I was looking deeper into the docs for Hue. It actually looks like they now prefer mDNS for discovery. I actually implemented a mDNS scanner in this architecture as an additional scanner. I did see that there are several scanners at play, prioritized by preferred scanning methods first. Which would make stop() or cancel() a little tricky. I was just thinking that it would be nice to cleanup the scanners if the user decided to stop waiting for scanning. etc...

@NilsLattek
Copy link
Collaborator

As a workaround: I guess you could just remove the delegate and dealloc the object. It would still run in the background until the internal timeout is finished and then it is removed, but it won't call the delegate methods. Not the nicest way though, but should work.
Feel free to create a PR which implements the missing stop functions for the requests or new scanners. We would be happy to have some help.

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