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

Merging LE Secure Connections Multirole Example and Ble App UART Example

Hi,

I am working on a project where I need to send and receive ASCII strings from my Central Device to the Peripheral Device. Before the communication starts there should be a bonding (paring) between the devices. The nRF52840 DK is used as a peripheral device and nRF Toolbox is used as a central device.  After the bond is established the text should be encrypted using the AES algorithm. Finally, the text sent should be displayed using UART.

the bonding and paring are done in example LE Secure Connections Multirole and the UART is done in the example Ble App UART so I wanted to merge both the files. Can anyone help me with this?

The tools and software used are listed here:

NRF52840 DK

SDK 15.2.0

Segger embedded studio for coding

nRF Toolbox version 2.0

Parents
  • You don't need to merge the two examples completely, I would instead recommend you to add the security related functionality to the BLE App UART example. In addition I don't think the nRF Toolbox supports bonding with the BLE UART example. You should use nRF Connect (for phone) instead.

    I would recommend you to take a look at the Peer Manager, which is a library that can be used to manage BLE Security. If you take a look at the different Message Sequence Charts for LESC Pairing, you can see that pairing consist of a set of events and replies. The Peer Manager will handle most of this for you.  

    In order to initialize the Peer Manager you have to execute the three steps explained in this link. Then, depending on the pairing method, you have to set the Security Parameters accordingly. 

    Choose pairing method and set security parameters

    The LE Secure Connections Multirole examples uses the pairing method Numeric Comparison, but you have other choices, such as Numeric comparison, Out of Band, Passkey Entry and Just works. Check out this link on how to set the security parameters for the different pairing methods.

    Initialize the Peer manager

    In order to initialize the Peer Manager you have to run the three steps, as explained here:

    Include functionality depending on pairing method

    Depending on the pairing method, different functionality must be implemented. E.g. if you want to use Numeric Comparison, you need a way of displaying the comparison numbers when receiving BLE_GAP_EVT_PASSKEY_DISPLAY, and also functionality to press a button and respond with sd_ble_gap_auth_key_reply(). This will make more sense of you look at the Message sequence chart for Numeric Comparison. The function nrf_ble_lesc_request_handler() should run regularly in the main loop (Take a look at the The LESC Multirole example on where to put it).

    If you want me to go through any of the other pairing methods, please ask. 

    Remove BLE event replies from the BLE App UART examples

    The ble app uart example includes a ble_evt_handler(), which will receive and reply to BLE events, including some that will interfere with the Peer Manager and the pairing process. You should comment out the replies to these events: BLE_GAP_EVT_SEC_PARAMS_REQUEST and BLE_GATTS_EVT_SYS_ATTR_MISSING.

    I may have forgotten something, but this should be a good start. Please ask if anything is unclear.

    Best regards,

    Simon

  • Thank You for explaining the initial steps.

    I have included the peer manager function in my UART example with numeric comparison security features.
    When I try to connect my nRF board with the new UART example( including security features) it shows connected initially but while bonding and pairing it throws an error stating:

    ERROR: (0x16): GATT CONN TERMINATED LOCAL HOST.

    The screenshort of the nRF Toolbox app UART logs is attached below:



    As you told me previously that nRF toolbox doesn't support BONDING and PAIRING so I tried to connect using the nRF Connect App but still I am getting the same Error.

    Am I missing anything If so please help me!

  • Hi,

    As I told earlier, now the bonding and pairing are working. I am able to send and receive strings from my central and peripheral device.

    I needed a small help now.

    Actually, I don't want to send strings from my nrf52840 board(via PUTTY). If I send a text from my central device to my peripheral I should get an automatic reply with some string.

    Can you tell me where should I make changes to implement this?? 

  • Actually what I meant from my previous question is that only central device that is nRF Toolbox app should send strings and get an automatic reply from the peripheral that is the nRF52840 board.

  • Hi, I went through one of your post (link attached below).

    https://devzone.nordicsemi.com/f/nordic-q-a/36397/how-to-send-data-from-nordic-nrf52840-to-ble-android-app-nrfconnect

    Can you please tell me where and how to use ble_nus_string_send(&m_nus, data, sizeof(data)) in my code mentioned above to get a text from the nrf52840 board.

  • APP_TIMER_DEF(send_some_uart_data);    /**< Some timer */
    
    void send_some_uart_data_handler(void * p_context)
    {
        ret_code_t err_code;
        
        uint8_t string[] = "serial updated\n\r";
        uint16_t length = sizeof(string);
        
        do
        {
            
            err_code = ble_nus_string_send(&m_nus, string, &length);
            if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) )
            {
                APP_ERROR_CHECK(err_code);
            }
        } while (err_code == NRF_ERROR_BUSY);    
    }
    
    void send_some_data_uart_init(void)
    {
        app_timer_create(&send_some_uart_data,APP_TIMER_MODE_REPEATED, send_some_uart_data_handler);
        app_timer_start(send_some_uart_data, APP_TIMER_TICKS(1000), NULL);
    }
    
    // Call send_some_data_uart_init(); in main() to run send_some_uart_data_handler() at configured internal.
    

    I added this part into my code for sending a fixed string from my nRF52840 board. But I get an error stating:

    Output/ble_app_multirole_lesc_s140_pca10056 Release/Obj/main.o: In function `send_some_uart_data_handler':
    1> C:\nRF5_SDK_15.2.0_9412b96\nRF5_SDK_15.2.0_9412b96\examples\ble_central_and_peripheral\experimental\ble_app_multirole_lesc/main.c:1386: undefined reference to `ble_nus_string_send'
    Build failed

Reply Children
No Data
Related