Hi everybody,
I'm trying to hide some characteristics till the user write the right value to a secure pin characteristic the devise exposes at the beginning.
I already did it but, when the user disconnects his device and repeat the pairing procedure, then the hidden characteristics are shown twice and, if hi continues, thrice and so on.
So, reading this post on the Nordic Developer Zone , I should disable the soft device, in order to remove the entire GATT database, and then enable it again.
I'm trying to do this by calling the function services_destroy()
in the BLE_GAP_EVT_DISCONNECTED
of the on_ble_evt(ble_evt_t * p_ble_evt)
, but this causes a chip reset.
void services_destroy(void)
{
uint32_t err_code;
err_code = sd_softdevice_disable();
if(err_code != NRF_SUCCESS)
{
UART_TxLogDebug(MODULE_NAME(BLE_CUSTOM),LOG_ERROR,FUNC,INFO_Y,2,
UART_STRING("err_code = "), UART_UINT32(err_code, HEX));
}
APP_ERROR_CHECK(err_code);
ble_stack_init();
}
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
uint32_t err_code;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
UART_TxLogDebug(MODULE_NAME(BLE_CUSTOM),LOG_INFO,FUNC,INFO_Y,1,\
UART_STRING("BLE_GAP_EVT_CONNECTED"));
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
#ifdef INSERT_PIN_ENABLED
ble_state = BSP_STATE_PAIRING;
one_sec_timer_start();
config_service_variable.security_pin.pin_timeout = TIME_OUT_PIN;
config_service_variable.security_pin.pin_insertions = 0;
#else
ble_state = BSP_STATE_READY;
#endif
#ifdef ADC_CUSTOM_ENABLED
//Battery Level reading
adc_enable();
#endif //ADC_CUSTOM_ENABLED
break;
case BLE_GAP_EVT_DISCONNECTED:
UART_TxLogDebug(MODULE_NAME(BLE_CUSTOM),LOG_INFO,FUNC,INFO_Y,1,\
UART_STRING("BLE_GAP_EVT_DISCONNECTED"));
#ifdef HIDE_CHARACTERISTICS_BEFORE_PIN
services_destroy();
services_PIN_init(FALSE);
#endif //HIDE_CHARACTERISTICS_BEFORE_PIN
m_conn_handle = BLE_CONN_HANDLE_INVALID;
#ifdef BLE_BEACON_ENABLED
ble_state = BSP_STATE_BEACON;
#else
ble_state = BSP_STATE_ADV;
#endif
#ifdef INSERT_PIN_ENABLED
one_sec_timer_stop();
#endif
#ifndef BLE_BEACON_ENABLED
application_ble_advertising_start();
#else
beacon_advertising_start();
#endif
break;
default:
// No implementation needed.
break;
}
}
Guessing the issue was caused by the wrong position of the calling of the sd_softdevice_disable()
I tried to put it in the main function, but I got the same result!
What am I doing wrong? Any suggestion? Thanks in advance:
Massimo Pilia