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

Error of scan BLE device #11

Closed
kennyjudo opened this issue Jun 28, 2018 · 12 comments
Closed

Error of scan BLE device #11

kennyjudo opened this issue Jun 28, 2018 · 12 comments

Comments

@kennyjudo
Copy link

  • bleak version: 0.2.0
  • Python version: 3.6.5
  • Operating System: Win10, vscode and spyder

Description

I have a problem on the BLE device scan operartion, when I use the example code, it can detect and show the nearly BLE device, however, when I turn the device off, and run the program again, its still show up the device which is turned off, i think some info is saved and reload , how can I make a clear or initialize so that to prevent this issue?

for example, I turn off The Smart LED 4A72 and run the code, its still show up after I run the code
scan errror

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
@hbldh
Copy link
Owner

hbldh commented Jun 28, 2018

The Windows Bluetooth API has a delay before it removes a Bluetooth device from its internal list, and it only seem that it only removes it after it has been gone while actively scanning for a certain amount of time. Thus, to ensure that devices you turn off are actually removed, increase the timeout of the discover call to longer than the default 5 seconds:

devices = await discover(10.0)

If you add the environment variable BLEAK_LOGGING=1 and then run the discover.py, then you will see logging about how devices are added, updated and removed from enumeration of devices.

@kennyjudo
Copy link
Author

kennyjudo commented Jun 28, 2018 via email

@kennyjudo
Copy link
Author

kennyjudo commented Jun 28, 2018 via email

@hbldh
Copy link
Owner

hbldh commented Jun 28, 2018

I know. The entire block could be deleted, but I want keep it for trying to get it to work eventually.
It is not the source of your problems though; it still updates information in found, since that code is outside the try-except block.

I cannot reproduce your problem I am afraid. For me a turned off device is really removed from the scanning. Are your running the code in VSCode then try to reproduce it from the terminal.

Are you sure the device is not broadcasting? Scan with your phone or any other BLE scanning-capable device to see that it actually should not be visible.

@kennyjudo
Copy link
Author

kennyjudo commented Jun 28, 2018 via email

@hbldh
Copy link
Owner

hbldh commented Jun 28, 2018

That's why I think you should run it in terminal; I do not know how VSCode handles loading of modules. Bleak in itself does not log or save anything of that sort. Try to see it the same behaviour is present when running in terminal.

@hbldh hbldh closed this as completed Nov 30, 2018
@Surgavery
Copy link

I'm having the same issue. Have you found any solution?

@hbldh
Copy link
Owner

hbldh commented Jun 25, 2019

@Surgavery As I said in the last comment:

That's why I think you should run it in terminal; I do not know how VSCode handles loading of modules. Bleak in itself does not log or save anything of that sort. Try to see it the same behaviour is present when running in terminal.

@Surgavery
Copy link

Hi Henrik and thanks for the fast response,

The same behaviour is observed using the Python Terminal. I install a new BLE adapter and the list of devices starts empty. However, if a discoverable device is found it remains in the list besides being disconnected.

Any suggestions?

@hbldh
Copy link
Owner

hbldh commented Jun 25, 2019

Ok, then we have established that at least.

What do you think a solution might be? A clear method?

Though I fail to see how this is a real problem? It does most certainly not qualify as a bug in Bleak, since it is a true representation of what the native backend reported. It is not like the list of discovered devices is a completely trustworthy source of information that you can depend upon anyway?
In my opinion, I cannot make assumptions on my own regarding a device's trustworthyness or possible false presence in the list, but it is better for me to report what the native service conveys and let the user try to connect or filter on RSSI strength and disregard them after that.

I think the OS retains the devices for a while after they have stopped receiving BLE advertisments from them, since the advertising solution in itself is a not a surefire solution. After how long is it reasonable to remove the device from discovered devices due to missing advertisements? Too short gives a flaky and hard to rely upon solution, too long might lead to the feeling portrayed in this issue. These kinds of decisions are far outside the scope of Bleak to make.

@Surgavery
Copy link

I agree! Is not a real major problem, simply is quite annoying seeing such large list of devices.

@hbldh
Copy link
Owner

hbldh commented Jun 26, 2019

You can filter the discover results on signal strength to make the list consist of only closeby devices:

devices = await discover()
# Filter away all devices with signal strength less than or equal to -60 dBm
# Windows version
filtered_devices = list(filter(lambda x: x.details.RawSignalStrengthInDBm > -60, devices))
# Linux version
# Will add this shortly

Maybe your turned off device is still present in the list, but with a very low signal strength.

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

3 participants