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

Parents
  • 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?

  • 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

  • The missing thing here might be step 1 from Lesson 5, exercise 1.

    One will need to modify the characteristic configuration so that it requires encryption. Otherwise bonding will not automatically be performed, even if one sets CONFIG_BT_NUS_SECURITY_ENABLED=y.

    Andreas Schurz said:
    And the bonding workes for you?

    Yes. One can also request bonding from the phone, either with nRF Connect for Mobile => Connect (click the three dots) => Bond. Or you could use the phone's Bluetooth menu.

    The logs are routed to RTT so that the UART can be used for NUS.

  • Hi Helsing,

    sorry for the delay but there were other tasks.

    Could you tell me precisely where to add the code block in order to make the example work so that it requires bonding? Problem is that it already has the GATT-Server enabled somehow internally and I have no idea how to exactly overwrite the existing setting.

    Many thanks so far.

    Regards, Andreas

Reply Children
  • I guess I figured it out myself - in the meantime.

    prj.conf mostly

    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_SMP=y
    CONFIG_BT_SMP_SC_ONLY=y
    CONFIG_BT_BONDABLE=y
    CONFIG_BT_NUS_SECURITY_ENABLED=y
    
    CONFIG_BT_PRIVACY=y
    CONFIG_BT_USE_DEBUG_KEYS=n

    main.c

    static void connected(struct bt_conn *conn, uint8_t err)
    {
        if (err) {
            printk("Connection failed (err %u)\n", err);
            return;
        }
    
        printk("Connected\n");
    
        /* Claim at least security level 2 */
        if (bt_conn_set_security(conn, BT_SECURITY_L2)) {
            printk("Failed to set security level\n");
        }
    }

    Could you confirm that this is the proper solution?

    Many thanks in advance.

    Regards, Andreas

Related