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

Function execution when BLE_GAP_EVT_CONNECTED

Hello,

I am using ble_app_uart code. My first goal is to execute a function when board connects with an android device. Another goal is to disconnect board from an android device after information was sent. Moreover, to uninitialize radio, advertising execution for defined time interval after board gets disconected .

  1. Can I execute function from here? Or there should be a flag created in here and raised, then function executed in an eternal loop?

           static void on_ble_evt(ble_evt_t * p_ble_evt)   
            /*Function for the Application's S110 SoftDevice event handler*/
     {
         uint32_t                         err_code;
         static ble_gap_evt_auth_status_t m_auth_status;
         ble_gap_enc_info_t *             p_enc_info;
         
         switch (p_ble_evt->header.evt_id)
         {
             case BLE_GAP_EVT_CONNECTED:
                 nrf_gpio_pin_set(CONNECTED_LED_PIN_NO);
                 nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO);
                 m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
              					
     	        nrf_gpio_pin_write(GPIO_TOGGLE_COMPARE_EVENT, 0);
     		sprintf(siusti_plnasete8,"CONNECTED");
     		ble_nus_send_string(&m_nus,siusti_plnasete8,10);
     		
    
                 break;
     				
    
  2. Where should I receive an indication that information was sent? I would use it to disconnect my board.

Parents
  • Hi,

    If you want to send any BLE packets to the peer right before you disconnect (sd_ble_gap_disconnect()), you should to wait for confirmation that the peer have received the packets before you disconnect. You should therefore set a flag, and wait for confirmation before disconnecting.

    For indication, a BLE_GATTS_EVT_HVC event will be issued as soon as the confirmation arrives from the peer. For notification, you should wait for the BLE_GATTS_EVT_HVN_TX_COMPLETE event instead.

Reply
  • Hi,

    If you want to send any BLE packets to the peer right before you disconnect (sd_ble_gap_disconnect()), you should to wait for confirmation that the peer have received the packets before you disconnect. You should therefore set a flag, and wait for confirmation before disconnecting.

    For indication, a BLE_GATTS_EVT_HVC event will be issued as soon as the confirmation arrives from the peer. For notification, you should wait for the BLE_GATTS_EVT_HVN_TX_COMPLETE event instead.

Children
Related