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

  • Hi Andreas, 
    I'm taking over the ticket. Sorry for the late response. 
    At lesson 5 we cover security and bonding. Have you looked at the lesson ? 
    By having

    CONFIG_BT_SMP=y 

    CONFIG_BT_BONDABLE=y ( by default enabled when you enable SMP) 


    Your application should be able to handle bonding.

  • Hi Hung,

    yes but I initially had no idea how to force / require the Lesson 4 NUS example to use bonding in order that it is not working without. There is already commented code inside which should do this but actually did not, i. e. I was able to use it with or without bonding.

    My requirement was to force the bonding in order to use the service.

    I have posted a possible fix for this here and just wanted to be sure that this is the proper solution. We are planning to use the NUS implementation with bonding for a commercial solution within DHL and I just want to make sure that the implementation is right on point.

    Regards, Andreas

Related