-
Notifications
You must be signed in to change notification settings - Fork 7.6k
BLEScanResults getcount() returns zero in 1.0.5-rc4 #4627
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
Comments
I have changed
|
Yes you're correct. It seems the change was such that if you set a callback it would not insert the device into the scan results map. It should work if you don't set a callback and parse the results after. |
I see. But this is really a problem : I need a callback to be able to count the detected device and stop the scan after a threshold. Otherwise the scan ends up crashing. I refer to this issue: #3559 So without the callback this will not work. Any chance this will be fixed? |
I'm not sure what you're code is doing but to avoid the crash issue that you linked you could call |
Your are very right: when I remove the "setAdvertisedDeviceCallbacks" getCounts returns a value even in 1.0.5 In my case, I need to limit the nember of detected device in a SINGLE scan. A single scan was enough to make the crash happen so I have no time to call for clearResults. This is what happened to me in an environment with hundreds of ble beacons (the hall of a trade show). my callback is only a counter that stops scan after a threshold:
Looking at BLESCAN.cpp the issue is right there. in 1.0.5 there is a condition (as you saw it) that says: " if has callback, no need to record to vector". This is what's causing my issue. This was probably inserted for a reason. But how can I achieve my goal without a callback (that is to interupt the scan after a threshold before the scan crashes because there are too many devices) in 1.0.4:
While in 1.0.5-rc4:
|
Looks like a workaround would be just to use the callback but create your own vector of devices and limit it in your application. The suggestion to add a limiter on the number of devices is also a good idea. |
The official code example is also broken as a result ( |
So as a summary from 1.0.5, the code was changed so that if there is a callback set, the code supposes that the user will do all the device detection data collection in the call back. Therefore it does not create the array of detected devices. Before 1.0.5 both were happening: callback+constructing the array. It was changed in commit #3995 (actually the first commit was ok, but a additionnal change was brought and broke my usecase) I tested a VERY easy fix: I just removed one "ELSE" in 1.0.5-rc6:
I tested and it works fine again. not sure what to do I will start with a comment on the problematic commit... |
Yes that seems to be the purpose of the commit. Good fix IMO. I have recently implemented the ability to cap the number of scanned devices in the NimBLE library, inspired by your use case. If you don't need classic bluetooth, you might want to try NimBLE, it'll also save a lot of ram and flash. |
Thanks, I might give it a try indeed |
@h2zero @Ben79543 Has there been any updates regarding this issue? I recently updated to release 1.0.6 and now when scanning I get multiple duplicates of the same device and sometimes it even crashes the ESP32. I tried playing around with the |
I'm not aware of any changes that would affect this issue. If you don't need classic Bluetooth I suggest using NimBLE as it works the way you'd expect and probably only requires a header change in your code. |
Thanks for the recommendation. I'll certainly will give it a go. |
Proposed fix to espressif#4627 as a remediation to PR espressif#3995 espressif#3995 introduced that a device detected on BLE would not be entered in vector if a callback has been defined. By doing so, it was not possible anymore to have a counter in a call back (AND device in vector) to limit the number of detected device in a single scan, which could crash ESP32 as a result.
I have created a PR for this : #5241 |
Proposed fix to #4627 as a remediation to PR #3995 #3995 introduced that a device detected on BLE would not be entered in vector if a callback has been defined. By doing so, it was not possible anymore to have a counter in a call back (AND device in vector) to limit the number of detected device in a single scan, which could crash ESP32 as a result.
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
I know this is old, but is there any chance someone made this example work with extended advertising? In this case the data comes in the scan response data instead of the advertising data, what do I need to change to detect that? |
I have tried to run the standard supplied BLE_scan.ino example code - not a single change to it.
It's running fine when I am on 1.0.4 - I get the list of detected devices, and it tells me "found devices: 6" for instance.
When I switch (via board manager) to 1.0.5-rc4:
Something broken with getCount()?
Hardware:
Board: ESP32 Dev Module
Core Installation version: 1.0.4 and 1.0.5-rc4
IDE name: Arduino IDE 1.8.12
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10
Logs with 1.0.4 (working): (note I remove the middle lengthy part)
LOGS with 1.0.5-rc4 (note I remove the middle lengthy part)
The text was updated successfully, but these errors were encountered: