Beacon transmission during scanning (about scanning and advertising scheduling)

I am building a system that periodically emits a beacon (ADV_NONCONN_IND) at the same time as scanning the central role using S132 v7.2.0.

Regarding the subject, when I checked the past Q&A, I recognized it as follows.

  1. The devices cannot scan and advertise at the same time. When adv role overlaps scan role, it round robins.
  2. The scan timing is defined by setting ble_gap_scan_params_t::.interval and .window in nrf_ble_scan_init(), and scanning is performed for the period of .window every .interval from the time of nrf_ble_scan_start().
  3. The advertise timing is defined by setting ble_gap_adv_params_t::.interval with sd_ble_gap_adv_set_configure(), and is sent at intervals of .interval from the time of ble_advertising_start().

For example, if you set scan_interval=1000ms, scan_window=1000ms(100% scanning), adv_interval=100ms and set scan_start and advertising_start at the same time, scan and adv (9-10 times) will be performed every 1000ms.
Also, if you set scan_interval=100ms, scan_window=50ms(50% scanning), adv_interval=100ms, alternately repeat adv with 100ms interval (9-12 times) and adv with 200ms interval (4-5 times), maybe 200ms It is considered that scanning is performed in between.

The goal is to send a stable 100ms advertising beacon and scan in the free timeslot.

As a trial, setting scan_interval=50ms, scan_window=40ms (80% scan), adv_interval=100ms resulted in a stable advertisement every 100ms.
What is the scan window at this time?

How do I adjust these parameters for the timeslot scheduling rules?

Also, it would be nice to be able to visually check the scan window using a sniffer, is there a better way? It would be nice if the scan window state could be output on/off at the port.

best regard.

  • Hi Hiroyuki, 

    The easiest way to detect the actual scan window is to use the power profiler. You can also use an oscilloscope for that task as well. 
    By looking at the power consumption you can detect the period when the device is doing advertising or when it's doing scanning (or when the radio is not active at all). 

    If you have a look at the S132 specification here. You can find that advertising and scanning are both on the same third priority. When you do both activity together they are scheduled in first come first serve manor. 
    Note that when you do advertising at 100ms interval the whole interval period will be reserved for the advertising. The scheduler was not designed to take advantage of the fact that the actual advertising only take a few ms compare to the whole 100ms interval. 

    Same applied for scan windows and scan interval. Even though the scan window only takes a small part of the scan interval but the whole period of the scan interval is reserved for the scanning task. 

    I would suggest to use the power profiler to find the best option for you to balance between scanning and advertising. 

  • Hello Hung Bui,
    Thanks for your quick reply.
    I've seen some articles using power profiler to visualize scan windows.
    That is a method of indirectly determining the communication state from the power consumption of the BLE controller.
    However, as far as I could see the waveform, it was noisy and the time accuracy didn't seem to be very good.
    For example,if other sequences such as CONNECTION are mixed in addition to SCAN and ADV, I think it will be impossible to distinguish between them.
    If possible, I would like to make it a digital output in order to observe it in synchronization with the communication frame on the elisys BLE Analyzer.
    .I think that if the scheduler's interrupt interception and the state at that time can be known in a register or RAM, the desired signal can be generated, but is there a way?
    I have an additional question.
    If the timing of scan_start and advertise_start shifts due to a restart, etc., won't the optimized time parameters also shift?
    If so, what can be done to prevent it?
    • When restarting scan or advertise, stop both and then start them at the same time.
    • Set the interval between scan and advertise to an integer multiple to synchronize intervals without deviation.
    • etc···

    best regard.

  • Hi again Hiroyuki, 

    Could you please send us the waveform you have ?

    From my experience it shouldn't be too hard to detect the scan period, advertising activity and connection activity. Each of them has a distinct characteristic. For example advertising usually done on 3 consecutive packages . Connection usually transmitting and receiving in one single event. And scanning usually keep the radio in RX mode for the whole period. If you do scan window of 50ms you should be able to detect such period in high current consumption.  

    It's pretty easy to spot them with human eyes but maybe not straight forward  if you want to automatically detect the activity by some code (possible though)

    I understand that it's easier if there is an API that exposes the activity of the softdevice but it's not available. 

    It's possible to use GPIO and PPI to connect to events in the RADIO to detect if it's RX or TX active :

    But it's only available on nRF52840. You may think of using the nRF52840 to do profiling. The scheduling should be the same on nRF52832. 

    Regarding your question, as far as I know, it's correct that stop and start scanning or advertising may potentially make the optimized time shifted. It's the nature of the scheduler that it was designed with more focus on robustness and simplicity. 

    I haven't looked at the exact implementation by my understanding is that every time you stop and start an advertising or scanning it will be the scheduled same as when you start them by new. 

    It's hard for me to give you a strategy without knowing what exactly you want to achieve and the common configuration you have. But I would suggest to try with the PPK and check if you can find an easy way to achieve the optimized scheduling. 

  • Hi Hung Bui,
    Thanks again for your quick reply.

    I understand that each power profiler has a characteristic pattern.
    I haven't taken the actual waveform yet, so let me ask you another question when you don't understand the pattern.


    Thank you very much for all the helpful information.

  • Hello Hung Bui,
    I haven't made much progress on the issue, so any advice would be appreciated.

    From the answers so far, I understand that advertising and scanning are the same 3rd priority, and if you do both activities together they will be scheduled on a first come, first served basis.

    I understand that the advertise interval and scan interval are reserved by the scheduler for the entire interval, but is there a way to control this?

    I want the scanning window for catching ads to be as wide as possible, and outside that window we want to send beacons every 100ms(not required).

    Possible plans is ...

    1. Set advertise Interval to 100 ms and observe and adjust Scan Interval and Window in Power Profiler.
    2. Revamp the scheduler so that ads and scans can be scheduled together.
      In that case, for example, can I change the priority of the ad scanner?
    3. Since it is difficult to achieve with one chip, divide the scanner and beacon device into two (last resort)
    4. Can you think of anything else?

    By the way, when connecting with scan_interval=1000ms and scan_window=1000ms, it has been confirmed that there will occasionally be a no-communication band that does not even output 1000ms of no empty packet(as if it is frozen) after resuming scanning after connecting.
    I want to prevent this phenomenon as well.

    best regard.

Related