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

Nus service and disconnecting at 7th time

Hi, I'm having an issue, when i compare the data received over BLE NUS SERVICE, i want to choose stay connected or disconnect to the device..(if i don't receive the data that i want i call disconnect function)... I'm using sd_ble_gap_disconnect(m_conn_handle,BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); to make a disconnection, then peripheral wait ~4seconds and start advertising again, but imagine that they connect and disconnect per 6 times well, when disconnect function is called the 7th time the central doesn't turn off the led of connect_led and does not start to scanning again the peripheral works right and advertising, i have to reset central device to work fine again.

this is the code to disconnect:

  static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
{

    for (uint32_t i = 0; i < length; i++)
    {
        data_recibida[i]= p_data[i];
            LEDS_ON(puerta_led | acceso_denegado );
              nrf_delay_ms(20);
            LEDS_OFF(puerta_led | acceso_denegado);
              nrf_delay_ms(20);

    }

            if((data_recibida[1] == 0x03) && (data_recibida[0] == 0x05)) {
                LEDS_ON(puerta_led | acceso_denegado );

            }
                else{
                    uint32_t err_code;
                    err_code= sd_ble_gap_disconnect(m_conn_handle,BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
                    if(err_code == NRF_SUCCESS){
                        LEDS_ON(puerta_led | acceso_denegado );
                  nrf_delay_ms(500);
                LEDS_OFF(puerta_led | acceso_denegado);
                  nrf_delay_ms(500);
                        LEDS_ON(puerta_led | acceso_denegado );
                  nrf_delay_ms(500);
                LEDS_OFF(puerta_led | acceso_denegado);
                  nrf_delay_ms(500);
                    }
                }



        }

the event BLE_GAP_DISCONNECT in the centralside is not called like the other last 6 time..

case BLE_GAP_EVT_DISCONNECTED:
        {
                      logi("me desconecte de nus periferico");

                        nrf_gpio_pin_write(24,0);
                      nrf_delay_ms(1000);
                  nrf_gpio_pin_write(24,1);


        } break; // BLE_GAP_EVT_DISCONNECTED
Related