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

Stop ble_app_uart connection with ble_app_uart_c

I am using: \examples\ble_peripheral\ble_app_uart  and  \examples\ble_central\ble_app_uart_c  .

In Nordic infocenter it says: The application scans peripheral devices and connects to a device that advertises with the NUS UUID in its advertisement report.

The questions are: 

1- Is this type of connection similar to a pairing where a key exchange occurs and connection is encrypted between peripheral and central?

2- How can I modify \examples\ble_peripheral\ble_app_uart code to drop the connection and reconnect periodically (for power saving) .

Parents
  • Hello,

    1. Pairing is a procedure that's performed after a connection is established to secure the connection. But pairing is not supported by the NUS example which means the link will always be unencrypted. The SDK examples that support BLE security include the Peer Manager module.

    2. You can use the low-power Timer library to trigger periodic events to start connectable advertising and/or terminate a connection.

    Softdevice function to terminate a connection:

                err_code = sd_ble_gap_disconnect(conn_handle,
                                                 BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);

    Required change in advertising_init() to prevent the advertising module from automatically re-starting connectable advertising on disconnect:

    /**@brief Function for initializing the Advertising functionality.
     */
    static void advertising_init(void)
    {
        uint32_t               err_code;
        ble_advertising_init_t init;
    
        memset(&init, 0, sizeof(init));
    
        init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
        init.advdata.include_appearance = false;
        init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    
        init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        init.srdata.uuids_complete.p_uuids  = m_adv_uuids;
    
        init.config.ble_adv_fast_enabled  = true;
        init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
        init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
        /* Don't restart advertising on discoonect */
        init.config.ble_adv_on_disconnect_disabled = true; 
        init.evt_handler = on_adv_evt;
    
        err_code = ble_advertising_init(&m_advertising, &init);
        APP_ERROR_CHECK(err_code);
    
        ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    }

  • Thanks Vidar. Is there any example that implements peer manager modules? 

    if NUS does not work with encryption and peer manager, how do I trans/receive data after encryption implementation? Which SDK modules I can use to communicate data between my two devices after connection encryption? 

  •  removed BLE_GATTS_EVT_SYS_ATTR_MISSING and BLE_GAP_EVT_SEC_PARAMS_REQUEST from both central and peripheral codes in ble_evt_handlers. 

    My central keeps resetting and prints this in COM port:

    <info> app_timer: RTC: initialized.
    <error> app: Fatal error
    <warning> app: System reset

    This is what appears in central code Debug terminal:

    <info> app_timer: RTC: initialized.
    <error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] 
    PC at: 0x00035A03
    <error> app: End of error report

    My peripheral does not print anything to the COM port. It is expected to print:

    Peripheral UART Started. 

    For peripheral this appears in the debug terminal:

    <error> app: Fatal error

    For both peripheral and central, debugger stops at: NRF_BREAKPOINT_COND in app_error_weak.c

  • Please select the "Debug" build configuration when debugging your project. This configuration includes the DEBUG flag which will make the error handler in app_error_weak.c print a more detailed error message.

  • Thanks Vidar. 

    For peripheral I get this in the debug terminal:

    <error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] at ...\nRF5_SDK_17.0.2_d674dde\components\libraries\log\src\nrf_log_backend_uart.c:67
    PC at: 0x000314CF
    <error> app: End of error report

    I set NRF_LOG_BACKEND_UART_ENABLED=0 in sdk_config and that seems to fix the issue. Now my peripheral device is blinking normal in scan mode. Please confirm.

    For central I get this in the debug terminal: 

    <info> app_timer: RTC: initialized.
    <error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] at ...\nRF5_SDK_17.0.2_d674dde\examples\My Projects\uart_central_wpmg_3\main.c:956
    PC at: 0x00035A03
    <error> app: End of error report

  • Hi,

    The UART driver is returning invalid state because you are application is trying to initialize the same UARTE instance twice, once by the logger module, and the other by the application (uart_init() in main). The solution is to only use RTT for logging and disable the UART logger backend by setting NRF_LOG_BACKEND_UART_ENABLED to '0' in sdk_config.h

  • Thanks Vidar. That fixed the problem and it is now working. 

Reply Children
No Data
Related