Nordic Developer Academy BLE NUS Example with Pairing and Bonding: various problems

Hi Support Team,

I am encountering various problems with the Developer Academy example found here:

https://academy.nordicsemi.com/courses/bluetooth-low-energy-fundamentals/lessons/lesson-4-bluetooth-le-data-exchange/topic/blefund-lesson-4-exercise-3/

1. Unable to debug without GATT errors

To overcome this issue I used logging but:

2. Logging is not working. None of the LOG directives is working

The cause why I need this is:

3. I set CONFIG_BT_NUS_SECURITY_ENABLED=y but nothing happend - security is not working

Could you tell me at least how to get the security in the example working?

Also logging is needed

Many thanks in advance.

Regards, Andreas

  • Thank you for the feedback. I will get back to you tomorrow.

  • Today I tried building and running blefund_less4_exer3_solution. First I verified that I could build the application and transfer data back and forth using nRF Connect for Mobile. Then I changed to CONFIG_BT_NUS_SECURITY_ENABLED=y and did a pristine build before flashing the application to nRF5340dk_nrf5340_cpuapp_ns. The sample worked as expected, using nRF Connect SDK v2.6.0.

    Have you tried building and flashing the solution?

    Which nRF Connect SDK version are you using?

    3. I set CONFIG_BT_NUS_SECURITY_ENABLED=y but nothing happend - security is not working

    How do you verify that security is not working?

  • Andreas Schurz said:

    The security implementation is already in the course example and can be activated by setting CONFIG_BT_NUS_SECURITY_ENABLED=y

    Code-Snipped - already within the code:

    One trick is to add a warning in your project, withing the ifdef for the kconfig that you are intending to use. That way the string you enter next to #warning will be printed when you build the code, only if that kconfig is active. See an example below:

    #ifdef CONFIG_BT_NUS_SECURITY_ENABLED
    #warning "Verifying that BT_NUS_SECURITY_ENABLED is enabled."
    static void security_changed(struct bt_conn *conn, bt_security_t level, enum bt_security_err err)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	if (!err) {
    		LOG_INF("Security changed: %s level %u", addr, level);
    	} else {
    		LOG_WRN("Security failed: %s level %u err %d", addr, level, err);
    	}
    }
    #endif

  • Hi Helsing,

    I have indeed built and flashed the application.

    I am expecting pairing, bonding and passkey exchange as implemented. This is working for other examples from the training but not this one. Instead I can Connect without any authentication and then send and receive data.

    It works just the same way it did before setting CONFIG_BT_NUS_SECURITY_ENABLED=y.

    One of the first things to happen right after connect is display the passkey:

    #if defined(CONFIG_BT_NUS_SECURITY_ENABLED)
    static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	LOG_INF("Passkey for %s: %06u", addr, passkey);
    }

    This is not happening for me.

    After this passkey has to be transmitted via app and confirmed on the board:

    static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey)
    {
    	char addr[BT_ADDR_LE_STR_LEN];
    
    	auth_conn = bt_conn_ref(conn);
    
    	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
    
    	LOG_INF("Passkey for %s: %06u", addr, passkey);
    	LOG_INF("Press Button 1 to confirm, Button 2 to reject.");
    }

    Which is also not happening for me.

    Tested on nRF52 with V2.6.1

    And the bonding workes for you?

    Regards, Andreas

  • Warning comes up then for me

    D:/bt-fund/lesson4/blefund_less4_exer3_solution/src/main.c:357:2: warning: #warning "Verifying that BT_NUS_SECURITY_ENABLED is enabled." [-Wcpp]
      357 | #warning "Verifying that BT_NUS_SECURITY_ENABLED is enabled."

Related