This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can't resume addvertising after disconnect.

I'm using the PSA1001 eval board with SD 110. The device comes up advertising, I can connect and access my services. I need to the Central to be able to issue a disconnect command, and for my device to disconnect and resume advertising.

I execute:

    sd_err = sd_ble_gap_disconnect 	( m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION	) ;
.
.
.
    advertising_start();

The return value is 0 (NRF_SUCCESS) - I do check the value of sd_err in my code, I just omitted it for carity here, as stated sd_err = NRF_SUCCESS after the call.

I then call advertising_start();

static void advertising_start(void)
{
    uint32_t             err_code;
    ble_gap_adv_params_t adv_params;

    // Start advertising
    memset(&adv_params, 0, sizeof(adv_params));

    adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
    adv_params.p_peer_addr = NULL;
    adv_params.fp          = BLE_GAP_ADV_FP_ANY;
    adv_params.interval    = APP_ADV_INTERVAL;
    adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;

    err_code = sd_ble_gap_adv_start(&adv_params);
    APP_ERROR_CHECK(err_code);
//    nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO);
}

I'm getting an NRF_ERROR_INVALID_STATE error from the sd_ble_gap_adv_start(&adv_params); call.

What am I doing wrong?

Thanks

  • I believe you have to wait for a BLE_GAP_EVT_DISCONNECTED event to be returned by the stack before you can restart your advertising. So, rather than calling advertising_start(); immediately after calling the sd_ble_gap_disconnect just add the advertising_start(); call in your disconnect event handler.

Related