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

SDk12 ble_app_hrs_rscs_relay has no BLE_ADV_EVT_IDLE in on_adv_evt

Hi I use ble_app_hrs_rscs_relay example with sdk12 and when the APP_ADV_TIMEOUT_IN_SECONDS is reach the nrf52 stop advertising but the on_adv_evt has no BLE_ADV_EVT_IDLE flag coming.

I do ble_advertising_start only now. Do I need call sd_ble_gap_scan_start on the same time with this example.

Thanks

  • Hi The whole Information like below: SDK: nRF5_SDK_12.1.0_0d23e2a Example Code: ble_app_hrs_rscs_relay MCU: nRF52832 on PCA10040 Board SD: 132 The Modify parts:

    static void adv_scan_start(void)
    

    { ret_code_t err_code; uint32_t count;

    //check if there are no flash operations in progress
    err_code = fs_queued_op_count_get(&count);
    APP_ERROR_CHECK(err_code);
    
    if (count == 0)
    {
        // Start scanning for peripherals and initiate connection to devices which
        // advertise Heart Rate or Running speed and cadence UUIDs.
        //scan_start();
    
        // Turn on the LED to signal scanning.
        LEDS_ON(CENTRAL_SCANNING_LED);
    
        // Start advertising.
        err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
        APP_ERROR_CHECK(err_code);
    }
    

    }

    #define NRF_CLOCK_LFCLKSRC      {.source        = NRF_CLOCK_LF_SRC_RC,            \
                                 .rc_ctiv       = 16,                                \
                                 .rc_temp_ctiv  = 0,                                \
                                 .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM}
    

    That are parts of example code I modify. and I set the

    #define APP_ADV_TIMEOUT_IN_SECONDS       20
    

    and the nRF52 stop advertising after 20 second but the on_adv_evt has no BLE_ADV_EVT_IDLE flag trigger.

    static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
    

    { switch (ble_adv_evt) { case BLE_ADV_EVT_FAST: NRF_LOG_INFO("Fast Advertising\r\n"); LEDS_ON(PERIPHERAL_ADVERTISING_LED); break;//BLE_ADV_EVT_FAST

        case BLE_ADV_EVT_IDLE:
        {
    				  NRF_LOG_INFO("BLE_ADV_EVT_IDLE\r\n");
            ret_code_t err_code;
            err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
            APP_ERROR_CHECK(err_code);
        } break;//BLE_ADV_EVT_IDLE
    
        default:
            // No implementation needed.
            break;
    }
    

    }

  • FormerMember
    0 FormerMember in reply to Vincent

    Okay, I see. Do you have added (registered) on_adv_evt (..) as the event handler in ble_advertising_init(..)?

  • static void advertising_init(void) { uint32_t err_code; ble_advdata_t advdata; ble_adv_modes_config_t options;

    // Build advertising data struct to pass into @ref ble_advertising_init.
    memset(&advdata, 0, sizeof(advdata));
    
    advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance      = true;
    advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    advdata.uuids_complete.p_uuids  = m_adv_uuids;
    
    memset(&options, 0, sizeof(options));
    options.ble_adv_fast_enabled  = true;
    options.ble_adv_fast_interval = APP_ADV_INTERVAL;
    options.ble_adv_fast_timeout  = APP_ADV_TIMEOUT_IN_SECONDS;
    
    err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL);
    APP_ERROR_CHECK(err_code);
    

    }

    Yes and I am not modify this part . The flag only on_adv_evt can get is BLE_ADV_EVT_FAST flag. It is showing fast when nRF52 power up.

    Thanks

  • FormerMember
    0 FormerMember

    The reason for the problem is a bug in ble_evt_dispatch():

    When there is a BLE event, the BLE events will be forwarded to the relevant modules based on the roles. However, when there is an advertising timeout, no role is assigned, and hence, the BLE event is not forwarded to the advertising module. The following line will make the advertising timeout being forwarded to BLE peripheral event handling:

    if ( (role == BLE_GAP_ROLE_PERIPH) || (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING) )
    

    Update 17.01.2017: To make sure that it is the advertising event that occurs, it is also necessary to check the event id, the code could then look like the following:

    if ( (role == BLE_GAP_ROLE_PERIPH) ||((p_ble_evt->header.evt_id == BLE_GAP_EVT_TIMEOUT) && (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING))  )
    {
        ....
    
  • FormerMember
    0 FormerMember in reply to Vincent

    The reason and a bugfix has been added in a second answer.

Related