Duration of BLE scan

newsettler_AI
Posts: 121
Joined: Wed Apr 05, 2017 12:49 pm

Duration of BLE scan

Postby newsettler_AI » Tue Jun 27, 2017 4:51 pm

Hi,

I want to increase scan window of BLE scan .

I found structure where described this parameters:

Code: Select all

    uint16_t                scan_interval;          /*!< Scan interval. This is defined as the time interval from
                                                      when the Controller started its last LE scan until it begins the subsequent LE scan.
                                                      Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms)
                                                      Time = N * 0.625 msec
                                                      Time Range: 2.5 msec to 10.24 seconds*/
    uint16_t                scan_window;            /*!< Scan window. The duration of the LE scan. LE_Scan_Window
                                                      shall be less than or equal to LE_Scan_Interval
                                                      Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms)
                                                      Time = N * 0.625 msec
                                                      Time Range: 2.5 msec to 10240 msec */
Looking for comment part it seems that max window I can get is 10.24 sec.

But at the same time I see this DURATION in esp_gap_cb function at this example
https://github.com/espressif/esp-idf/tr ... att_client

Code: Select all

    case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
        //the unit of the duration is second
        uint32_t duration = 30;
        esp_ble_gap_start_scanning(duration);
        break;
So, looks like it is possible to increase scan_interval more than ~10 sec? How about scan_window? I need about 30 seconds.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Duration of BLE scan

Postby kolban » Tue Jun 27, 2017 5:22 pm

The way I interpret this story is as follows:

scan_window - The interval of time during which a scan will be performed.
scan_interval - The interval of time between actual scans of duration defined in scan_window
duration - The interval of time over which total scanning will be performed before scanning stops.

For example .... imagine I wanted a scan to actively listen to radio for 100 msecs and not be scanning for 100msecs and perform this
for 10 seconds.

I might set:
scan_interval = 200msecs (question: this might be 100msecs)
scan_window = 100msecs
duration = 10 seconds

think of scan_window as interval when radio is actively receiving and scan_interval as interval between active receiving and duration as the amount of time to repeat the above.

In your story, if you want to radio receive continuously for 30 seconds (with the equivalent power being consumed) then:
scan_interval = 1 second.
scan_window = 1 second.
duration = 30 seconds.

In theory, this says that we will actively listen on the radio for 1 second ... since the scan_interval is also 1 second then the scan will complete immediately after the scan_window. The duration being 30 seconds means that we will repeat this for 30 seconds.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

newsettler_AI
Posts: 121
Joined: Wed Apr 05, 2017 12:49 pm

Re: Duration of BLE scan

Postby newsettler_AI » Thu Jun 29, 2017 3:44 pm

Thanks for explanation!
Hope that I am interpreting this correctly
interval_window_duration.jpg
interval_window_duration.jpg (40.02 KiB) Viewed 20029 times

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Duration of BLE scan

Postby kolban » Thu Jun 29, 2017 5:22 pm

That's a great diagram. What isn't clear to me from my reading is the notion of "interval" and how it relates to "window". The docs say that window must always be <= interval. This makes me think that an interval might be "the size of window plus the size between windows".

So for example, if window is 100 msecs and interval is 200 msecs, then there will be a scan for 100 msecs and then idle for the next 100 msecs and then this repeats for duration period.

I think we may find that if we set window to be 100msecs and interval to also be 100msecs, it might be that a scan executes for 100 msecs and then we find that "interval" has elapsed and we repeat immediately ... for duration in total... effectively a constant scan.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Greg_61
Posts: 3
Joined: Wed Apr 17, 2019 8:23 am

Re: Duration of BLE scan

Postby Greg_61 » Wed Apr 17, 2019 8:36 am

Hello. I wake up this post because my problem looks like :
I need to scan to know the name and RSSI servers every 100ms maximum. I am stuck because I can not reduce the duration parameter to less than 1s.
Thank you for your help

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

Re: Duration of BLE scan

Postby chegewara » Wed Apr 17, 2019 3:50 pm

https://docs.espressif.com/projects/esp ... g8uint32_t

What you can do is to have procedure where you call esp_ble_gap_stop_scanning after 100ms.

Greg_61
Posts: 3
Joined: Wed Apr 17, 2019 8:23 am

Re: Duration of BLE scan

Postby Greg_61 » Wed Apr 17, 2019 4:14 pm

Thank you for your answer but when I launch the procedure :

pBLEScan->start(scanTime, false);

I do not have my hand until the end of the procedure which lasts 1s ...

Greg_61
Posts: 3
Joined: Wed Apr 17, 2019 8:23 am

Re: Duration of BLE scan

Postby Greg_61 » Thu Apr 18, 2019 7:36 am

Hi, I understand better my problem : I can see in the callback definition inton BLEAdvertisedDevice.h :
  1. class BLEAdvertisedDeviceCallbacks {
  2. public:
  3.     virtual ~BLEAdvertisedDeviceCallbacks() {}
  4.     /**
  5.      * @brief Called when a new scan result is detected.
  6.      *
  7.      * As we are scanning, we will find new devices.  When found, this call back is invoked with a reference to the
  8.      * device that was found.  During any individual scan, a device will only be detected one time.
  9.      */
  10.     virtual void onResult(BLEAdvertisedDevice advertisedDevice) = 0;
  11. };

I would like this callback to be invoked at each scan and not once. Is it possible?

Who is online

Users browsing this forum: No registered users and 133 guests