Hello,
sd_ble_gap_adv_stop()
returns NRF_ERROR_INVALID_STATE
sd_ble_gap_disconnect(m_connx_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
Disconnects the device, but it reconnects in the following seconds.
Any idea?
Hello,
sd_ble_gap_adv_stop()
returns NRF_ERROR_INVALID_STATE
sd_ble_gap_disconnect(m_connx_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
Disconnects the device, but it reconnects in the following seconds.
Any idea?
By the way, as I wrote in the question, I want to stop advertising, but there's an error rising, even if I try to disconnect before stoppping advertising.
just don't advertise if you don't want to be connected to. If you want to stop everything, just disable ble.
if you are connected then you aren't advertising, even after you disconnect you're not advertising unless you restart advertising. So that's why stopping advertising gives you an error, because you aren't advertising.
if you are using the advertising module either configure it not to restart advertising after disconnection or change the code if there is no such option or stop using it.
ok here can be a clue : the variable systemState is set to systemOFF when I want to disable BLE and systemON when I want to enable BLE
static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
uint32_t err_code;
ble_gap_addr_t peer_address;
if(SystemState==SYSTEM_OFF)
sd_ble_gap_adv_stop();
switch (ble_adv_evt){
case BLE_ADV_EVT_DIRECTED:
break;
case BLE_ADV_EVT_FAST:
break;
case BLE_ADV_EVT_FAST_WHITELIST:
break;
case BLE_ADV_EVT_SLOW:
break;
case BLE_ADV_EVT_IDLE:
//sleep_mode_enter();
break;
case BLE_ADV_EVT_WHITELIST_REQUEST:
break;
case BLE_ADV_EVT_PEER_ADDR_REQUEST:
// Only Give peer address if we have a handle to the bonded peer.
if(m_peer_handle.appl_id != DM_INVALID_ID){
err_code = dm_peer_addr_get(&m_peer_handle, &peer_address);
APP_ERROR_CHECK(err_code);
err_code = ble_advertising_peer_addr_reply(&peer_address);
APP_ERROR_CHECK(err_code);
}
break;
default:
break;
}
}
Btw, how can we completely disable BLE? There is no documentation about that.