Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ble_app_hids_keyboard_pca10040_s112 example – how could disconnect?

I tried original ble_app_hids_keyboard_pca10040_s112 example, then modify it by moving the code for typing h.e.l.l.o   from Btn 1 to Btn3, and all possible combination of sd_ble_gap_disconnect and sd_ble_gap_adv_stop but as soon as I press the dedicated button for disconnect (long press on Btn1 in the original version or just click on the Btn1 in my modified version) the app disconnects, but immediately after reconnects Frowning2

//        case BSP_EVENT_KEY_0:
        case BSP_EVENT_KEY_2:
            if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
            {
                keys_send(1, p_key);
                p_key++;
                size++;
                if (size == MAX_KEYS_IN_ONE_REPORT)
                {
                    p_key = m_sample_key_press_scan_str;
                    size  = 0;
                }
            }
            break;
        case BSP_EVENT_KEY_0:
            NRF_LOG_DEBUG("Btn1 pressed");
             //sd_ble_gap_adv_stop(m_advertising.adv_handle);
             if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
             {			
                sd_ble_gap_disconnect(m_conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
             }
            sd_ble_gap_adv_stop(m_advertising.adv_handle);	
            // sleep_mode_enter();
            break;
ble_app_hids_keyboard2.zip

<debug> app: Btn1 pressed

<info> app: High Duty Directed advertising.

<info> app: Disconnected

<info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change

<info> app: Connected

<info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Encryption

<info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update, no change

<debug> nrf_ble_gatt: Peer on connection 0x0 requested an ATT MTU of 527 bytes.

<debug> nrf_ble_gatt: Updating ATT MTU to 23 bytes (desired: 23) on connection 0x0.

 

But I want to be able to disconnect  with no advertising and eventually go in sleep mode – the same way/ functionality when is not connected, but advertising and press Btn1.

How can achieve this?

Thanks

Parents Reply Children
No Data
Related