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

Stop the connection between a central nrf52832 and several peripherals nrf52832

Hello everybody !
Designing with the development board nRF52832 and SDK14.2.

My code is based on the code of the "ble_app_multilink_central" on which, I added some of the code "ble_app_uart_c" for the initialization and the event manager on the uart. I have a nrf52832 development board as a central and 2 rf52832 developpemtn boards as a peripheral.

In my uart event handle, I created several commands that I manage from my PC.
For example by pressing "1", I start scanning.

My goal is to add a function by pressing, for example "3", which allows to stop the connection with in my case the 2 peripherals with which is connected my central.

Using sd_ble_gap_disconnect is for me the solution but I do not see how to stop all connections.

Thank you in advance for your assistance !

Parents
  • I finally managed to design a system that allows me by pressure on:
    - "1" to start scanning / connecting to the 2 peripheral devices
    - "2" turn on an LED at my convenience (will be used later for something else)
    - "3" disconnect me peripherals with which I am connected

    void uart_event_handle(app_uart_evt_t * p_event)
    {
        static uint8_t data_array[30];
        static uint16_t index = 0;
        static uint16_t disco = 0;
        uint32_t ret_val; 
    
        static char const start[] = "1";
        static char const acquisition[] = "2";
        static char const disconnect[] = "3";
       
        /*static uint8_t test = 0x01;
        ble_gattc_write_params_t write_params = {0};
        write_params.write_op = BLE_GATT_OP_WRITE_CMD;
        write_params.handle = numconn_handle1;
        write_params.offset = 0x0000;
        write_params.len = sizeof(test);
        write_params.p_value = test;*/
        
        UNUSED_VARIABLE(app_uart_get(&data_array[index]));
    
        if (memcmp(start, data_array, sizeof(start)) == 0){
               //printf("start");
               scan_start();
               data_array[index] = 0;
        }
        else if (memcmp(acquisition, data_array, sizeof(acquisition)) == 0){
               //function to acquire values "characteristic"
               printf("LEDdebug");
               //sd_ble_gattc_write(numconn_handle1, &write_params);
               bsp_board_led_invert(LEDTEST);
               data_array[index] = 0;
        }
        else if (memcmp(disconnect, data_array, sizeof(disconnect)) == 0){
               //stop function BLE
               printf("disconnect");
               sd_ble_gap_disconnect(numconn_handle1,BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
               sd_ble_gap_disconnect(numconn_handle2,BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
               data_array[index] = 0;
        }
    }

    problem:

    After pressing "3" (disconnection), a few moments later, my central reconnects to 2 device without I press "1" (start scan).

    I even try following the connection to make a "sd_ble_gap_scan_stop ()" but no change:

        else if (memcmp(disconnect, data_array, sizeof(disconnect)) == 0){
               //stop function BLE
               printf("disconnect");
               sd_ble_gap_disconnect(numconn_handle1,BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
               sd_ble_gap_disconnect(numconn_handle2,BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
               sd_ble_gap_scan_stop();
               data_array[index] = 0;
        }

    If anyone can have a solution / line of thought.

  • problem: After pressing "3" (disconnection), a few moments later, my central reconnects to 2 device without I press "1" (start scan). I even try following the connection to make a "sd_ble_gap_scan_stop ()" but no change:

    The call to sd_ble_gap_disconnect() will initiate the disconnection procedure, and its completion will be communicated to the application with a BLE_GAP_EVT_DISCONNECTED event. By default the multi-link example will start scanning again when it gets the BLE_GAP_EVT_DISCONNECTED event. If this is not behavior you want, you can should comment out the call to the scan_start() function when you get the BLE_GAP_EVT_DISCONNECTED event.

    Snippet on how the example handles BLE_GAP_EVT_DISCONNECTED :

            case BLE_GAP_EVT_DISCONNECTED:
            {
                NRF_LOG_INFO("LBS central link 0x%x disconnected (reason: 0x%x)",
                             p_gap_evt->conn_handle,
                             p_gap_evt->params.disconnected.reason);
    
                if (ble_conn_state_n_centrals() == 0)
                {
                    err_code = app_button_disable();
                    APP_ERROR_CHECK(err_code);
    
                    // Turn off connection indication LED
                    bsp_board_led_off(CENTRAL_CONNECTED_LED);
                }
    
                // Start scanning
                scan_start();
    
                // Turn on LED for indicating scanning
                bsp_board_led_on(CENTRAL_SCANNING_LED);
    
            } break;

  • Thank you very much for the help, Sigurd. I succeeded thanks to your help. It was really stupid, I completely forgot the events ble with my event uart ... Ahah ...
    Thanks again !

Reply Children
No Data
Related