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

Beacon listener

I have beacon (ble_app_beacon) transmitting every 40...50 ms,  nRFConnect shows adv interval is ~44 ms, so it receives ~22 msg/sec.  My beacon listener gets only 10...12 msg/sec, below is (part) listener code. HW is nRF52832, SDK_15.1.0.

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
  ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;

    switch (p_ble_evt->header.evt_id)
    {   
        case BLE_GAP_EVT_ADV_REPORT:
        {
            rxCnt++;
            RED_TGL;	// toggle RED led
        }
            break;
        default:
            
            break;
    }
}


static void soc_evt_handler(uint32_t evt_id, void * p_context)
{
    scan_start();
}

static void ble_stack_init(void)
{
    ret_code_t err_code;
    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);
    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err_code);

    // Register handlers for BLE and SoC events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}

static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
    switch(p_scan_evt->scan_evt_id)
    {
        case NRF_BLE_SCAN_EVT_SCAN_TIMEOUT:
        {
            BLUE_TGL;	// toggle blue led
            scan_start();
        } break;

        default:
          break;
    }
}



static void scan_init(void)
{
    ble_uuid_t          target_uuid = 
    {
        .uuid = BLE_UUID_TX_POWER_SERVICE, //BLE_UUID_HEART_RATE_SERVICE,
        .type = BLE_UUID_TYPE_VENDOR_BEGIN //BLE_UUID_TYPE_BLE
    };
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;

    memset(&init_scan, 0, sizeof(init_scan));

    init_scan.connect_if_match = false; //true;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;

    err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);
    
}

static void scan_start(void)
{
    ret_code_t err_code;
    err_code = nrf_ble_scan_start(&m_scan);
    APP_ERROR_CHECK(err_code);
}

Parents
  • Hi,

    What scan window and scan interval are you using ?

    You are most likely using the values in sdk_config.h, NRF_BLE_SCAN_SCAN_INTERVAL and NRF_BLE_SCAN_SCAN_WINDOW

    Default is likely:

    NRF_BLE_SCAN_SCAN_INTERVAL 160
    NRF_BLE_SCAN_SCAN_WINDOW 80

    So in order to find more advertising packets per second, try setting NRF_BLE_SCAN_SCAN_INTERVAL to 80 , the scanner will then be on ~100% of the time.

Reply
  • Hi,

    What scan window and scan interval are you using ?

    You are most likely using the values in sdk_config.h, NRF_BLE_SCAN_SCAN_INTERVAL and NRF_BLE_SCAN_SCAN_WINDOW

    Default is likely:

    NRF_BLE_SCAN_SCAN_INTERVAL 160
    NRF_BLE_SCAN_SCAN_WINDOW 80

    So in order to find more advertising packets per second, try setting NRF_BLE_SCAN_SCAN_INTERVAL to 80 , the scanner will then be on ~100% of the time.

Children
Related