-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Scanning for bluetooth-devices works only once #3770
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
As it can be seen above, clearResults() is already used - so that does not solve anything. |
Like i mentioned in 2nd topic, library is not prepared to delete BLEScan object, but it can be easy fixed:
|
I already tried deleting m_pScan and reinitialising all the static variables before the next attempt but with no success, there are still no bluetooth devices found any more on second try. And: shouldn't this issue be fixed here in the repository as it is definitely a defect and other may stumble upon it too? That's the reason why I filed this bugreport... |
Then:
Feel free to create PR. |
I think the BLEDevice::deinit(true); is your problem. Make that a "false". deinit(true) releases internal parts of the bluetooth stack that cannot be reinitialized during runtime. |
@TheNitek the reason I'm doing it that complicated way is I'm low on memory. When I do not release the BLEDevice-memory as you suggested, this in no way helps as it does not releases the needed RAM. |
The documentation for esp_bt_controller_mem_release (which is called in case of "true") is pretty clear:
If you want to use bluetooth again, you cannot use "true". If you are only using BLE however, you can call |
OK, that fixed it - thanks! |
This workaround of re-initialising the BLE stack is fine when code is only scanning, but I am getting it with code that both scans and connects to devices. After a connection, it re-scans for further devices to connect to. |
This value is uninitialised and as such can be a random (and invalid) value. It's needs to be set per the espressif documentation here: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/bluetooth/esp_gap_ble.html#_CPPv4N21esp_ble_scan_params_t14scan_duplicateE This PR sets it to DUPLICATE_DISABLE. Chosen as this is needed to ensure all scan data is populated in the scan callback, per this comment in the IDF: https://github.com/espressif/esp-idf/blob/master/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c#L3591 "//if scan duplicate is enabled, the adv packet without scan response is allowed to report to higher layer" We **don't** want it to report to the higher layer (ie BLEScan.cpp) **unless** it has the active scan response. Seems to resolve #3770 #3677 and possibly others.
I have quite a complex application which is low on memory. From time to time this application scans for surrounding bluetooth devices. As the whole BLEScan-stuff consumes plenty of RAM, after such a scan everything is deinitialised to save the related memory:
My problem: this works well for the very first call. On the second and all following calls, no more bluetooth-devices are found, means BLEDevice::deinit() or BLEDevice::init() seems to be incomplete and probably leaves some variables back in a state, which avoids further successful scanning.
So my question: how can I reinitialise the whole BLE-stuff correctly in order to successfully scan the devices more than once?
Thanks!
The text was updated successfully, but these errors were encountered: