This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ble_app_hrs_c --scan stopped

I programmed nRF51822 with S120 softdevice and ble_app_hrs_c application to scan beacons. It works fine but have one problem.

  • It scans beacons for about 10 seconds then stop scanning for about 10 seconds and repeat scanning.

What makes this kind of symptoms scanning-stop-scanning-stop every 10 seconds period.

  • Could be lots of things.

    When you say stopped, do you mean the code has crashed, or that its still running but not getting the callback to indicate its receiving the advertising of beacons?

    Can you do something as simple as flashing a LED attached to one of the pins when the callback is called?

  • I have captured beacon data at "on_ble_evt" S120 reply event for 10 seconds then no reply for 10 seconds, I tested with one nordic format beacon.

    Symptom:

    • using one beacon every second advertising.
    • successfully scan beacon and send UART 10~11 times, it's about 10 seconds then halt
    • After about 10 seconds again scan beacon and send UART.
    • Repeat above situation.

    Durig halt state, I advertise anothe beacon then it scan successfully so this symptom is related in scanning same beacon continueously.

  • OK. So the code has not crashed, but the callback is no longer called for the first beacon, it only gets called for the second beacon which you turn on after 10 secs.

    What do you do in your callback ?

  • ...

    #define SCAN_INTERVAL              0x00A0                             /**< Determines scan interval in units of 0.625 millisecond. */
    
    #define SCAN_WINDOW                0x0050                             /**< Determines scan window in units of 0.625 millisecond. */
    

    Above is default setting interval I used. I mean that in the case I advertise only one beacon, it scans 10 seconds and stop 10 seconds then repeat scan and stop. During scanning stopped if I advertise another beacon, it scans another beacon.

  • Hi Mike

    From the discussion between you and Roger I suspect this pause for a few seconds is because of the periodic nature of both advertising and scanning. The scanning interval is set to 100ms with value 0x00A0 and the scan window is set to 50ms with value 0x0050. This means the scanner will scan 50ms, then pause 50ms, then scan 50ms, then pause 50ms, etc. The advertiser advertises however every 1000 ms. Since advertising period is a multiple of the scan interval, the advertiser could advertise many times in a row when the scanning is not scanning, i.e. in the scanning pause period. As Roger mentioned, if you blink a led when advertising packet is received, you will see this periodic behavior. You can fix this by scanning all the time, i.e. by setting scan window and scan interval to the same 0x00A0 value. You can also set the scan interval to e.g. 0x0090 to avoid the advertising interval to be a multiple of the scanning interval.

    Even though the advertising interval is a multiple of the scanning interval, the scanner is unlikely to miss the advertising packets forever, as there is added random delay of 10ms for every advertising event. If you for example set advertising interval to 100 ms, the time between two advertising events is actually between 100ms and 110 ms.

Related