Asynchronous/non-blocking BLE scan

afcec1
Posts: 23
Joined: Tue Oct 08, 2019 1:48 pm

Asynchronous/non-blocking BLE scan

Postby afcec1 » Thu Apr 08, 2021 1:32 pm

Hi,

I have quite a complex application already running on a custom board based on ESP32-WROOM-32D. I am using ESP-IDF 4.0 and managing Wi-Fi, Azure, etc... but now I need to add also BLE (Bluedroid) so my devices can work as clients connecting to one or several servers and consuming notifications from custom charactetistics.

As I said, the initial Wi-Fi application works just fine and the specific code I developed for BLE in an isolated project also returns good results. I have now integrated the BLE code with my existing project and one of the first issues I am experiencing is that when I start a BLE scan, the whole application gets blocked until the scan is finished. I do the BLE initialization from the main task and then I start the scan from a new task but the app still gets blocked. Is there any way to make somehow this scan process asyncrhonous? I mean, I have set the corresponding callbakcs so once I start the scan I only need the scan results notification on that callback. I saw something similar for Arduino coming from Neil Kolban but this feature does not seem to be consolidated into ESP-IDF, right?

Can anybody shed some light into this issue? Thanks!

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: Asynchronous/non-blocking BLE scan

Postby chegewara » Thu Apr 08, 2021 2:30 pm

BLE in esp-idf is events driven so it should not block your code. You can also read BLEScan class to see how it is solved in there.

afcec1
Posts: 23
Joined: Tue Oct 08, 2019 1:48 pm

Re: Asynchronous/non-blocking BLE scan

Postby afcec1 » Thu Apr 08, 2021 2:58 pm

chegewara wrote:
Thu Apr 08, 2021 2:30 pm
BLE in esp-idf is events driven so it should not block your code. You can also read BLEScan class to see how it is solved in there.
Thank you for your reply. Yes, that is exactly what I was expecting, an event-driven behaviour but in my case the application gets blocked as long as the scan is in progress (30 seconds). I will have a look at the BLEScan class.

afcec1
Posts: 23
Joined: Tue Oct 08, 2019 1:48 pm

Re: Asynchronous/non-blocking BLE scan

Postby afcec1 » Tue Apr 13, 2021 6:25 am

After further inspection I confirmed that the application was not getting blocked. It was only the primary UART used for serial communication with another device that, for some reason, was not sending new messages during the scan process.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 113 guests