-
Notifications
You must be signed in to change notification settings - Fork 304
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
Comments
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
If you add the environment variable |
Hi Henrik ,
Thanks for your reply, but the problems seems some data are log and save,
for the period example, I run the code again today, (keep The smart LED
4A72 turn off), it still show a list of BLE device which include "The
smart LED 4A72" that why I guess some info is saved or log in somewhere and
may without clear or initialize for new program run.
…On Thu, Jun 28, 2018 at 2:15 PM, Henrik Blidh ***@***.***> wrote:
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.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AmHB72NgKv1gK0pSID7CeCv5Zd108jZRks5uBHSWgaJpZM4U6nIg>
.
|
Hi Henrik,
more info, I add some break point to chase the discovery.py, I find that:
try:
watcher.Added -= DeviceWatcher_Added
watcher.Updated -= DeviceWatcher_Updated
watcher.Removed -= DeviceWatcher_Removed
except Exception:
logger.debug("Could not remove event handlers...")
it will always jump to the except so that it will not update the watcher at
the end and put info to found[]
…On Thu, Jun 28, 2018 at 3:04 PM, Kenny Chiu ***@***.***> wrote:
Hi Henrik ,
Thanks for your reply, but the problems seems some data are log and save,
for the period example, I run the code again today, (keep The smart LED
4A72 turn off), it still show a list of BLE device which include "The
smart LED 4A72" that why I guess some info is saved or log in somewhere and
may without clear or initialize for new program run.
On Thu, Jun 28, 2018 at 2:15 PM, Henrik Blidh ***@***.***>
wrote:
> 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.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#11 (comment)>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/AmHB72NgKv1gK0pSID7CeCv5Zd108jZRks5uBHSWgaJpZM4U6nIg>
> .
>
|
I know. The entire block could be deleted, but I want keep it for trying to get it to work eventually. 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. |
Hi Henrik,
I am using vscode IDE to run the program and I sure the BLE device is off
because I unplug it power manually. Its strange to me the problem I found
last night, than I turn my computer off and I can reproduce the same
problem today, that why I guess some BLE info may be log or save in
somewhere and not clear before I run the program,
…On Thu, Jun 28, 2018 at 4:46 PM, Henrik Blidh ***@***.***> wrote:
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.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AmHB74z2dmTDt54QrGaJ775JLGm__GxIks5uBJflgaJpZM4U6nIg>
.
|
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. |
I'm having the same issue. Have you found any solution? |
@Surgavery As I said in the last comment:
|
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? |
Ok, then we have established that at least. What do you think a solution might be? A 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? 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. |
I agree! Is not a real major problem, simply is quite annoying seeing such large list of devices. |
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. |
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
What I Did
The text was updated successfully, but these errors were encountered: