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

  • 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

  • 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