Simple Bluetooth Pairing using a Button, based on peripheral_uart example, not working

Hi guys,

I am trying to implement the possibility to have one central device made with a nrf52840DK and a peripheral with another nrf52840DK.

As I could have more nrf52840DK with the same BLE Name, I wanted to pair one particoular DK to the central, and be able to connect only to that board.
So, as I found bonding examples in the classic central_uart example, and in the perpheral example, I wanted to know how to use that part of the code, to implement this simple situation.


I am using the simple example of central_uart and peripheral_uart, I have went deep inside the KConfigs related, but I'm not able to see the activation of callbacks called 



even if they are configured properly, in the main() ...... is it normal ?
I also added, trying to check if it was a problem of KConfigs, this:


in the conf file, but nothing happens.

the callbacks are registered properly, but they are not called.
And the central connects without any pariring request to the peripheral.

I also tryed with nRF connect for iPhone, but the same result: directy connected to the peripheral.


 

I think it's a child game, but I'm not able to continue... 

Parents
  • Hello,

    To make iOS initiate pairing, you need to set CONFIG_BT_NUS_AUTHEN=y to require authentication for the NUS service and then try to access one of the NUS characteristics from the app. 

    log messages from the 'auth' callbacks:

    Best regards,

    Vidar

  • Hello Vidar,
    How are you ? Hope it's going on everything great.

    Now it works the NUS service auth. :-)

    But...I have a more generic question:

    Is there the possibility to implement this type of pairing autenticated with the device, at a level of connection (or at GATT level) ?

    I mean, in the real application, the situation is this:
    I have, e.g. 3 Centrals which has to be paired with respectively 6 peripherals, two for each central. they are in the same room.

    Previously I turned on one at time, and paired them with button accept request.



    Now, imagine to have all devices pre-autenticated in the same room, all turned ON.

    As the peripheral support 1 connection at time (or you can can set it to more than one, but it's not safe to set it to 10 for example I think), the fastest central connects to the P1 Green for example, keeps locked the peripheral as it's "CONNECTED BUT NOT AUTENTICATED FOR NUS SERVICE". 
    It's pre-autenticated with another central, but the connection keeps it locked.

    Well, how Can I implement this simple situation, allowing that only pre-authorized device can connect to my peripheral, and not every central ....? 

    Thanks Vidar!
    Enrico

  • Hi Encrico,

    I am doing good thanks. Hope you are too.

    enprevosti said:
    As the peripheral support 1 connection at time (or you can can set it to more than one, but it's not safe to set it to 10 for example I think), the fastest central connects to the P1 Green for example, keeps locked the peripheral as it's "CONNECTED BUT NOT AUTENTICATED FOR NUS SERVICE". 

    It may be better to change the security level from requiring authentication to encryption assuming you have limited IO capabilities on these devices. There is no Kconfig setting for this option. However, you can achieve it by manually replacing the BT_GATT_PERM_***_AUTH symbols with BT_GATT_PERM_***_ENCRYPT in your nus.c file.

    enprevosti said:
    Well, how Can I implement this simple situation, allowing that only pre-authorized device can connect to my peripheral, and not every central ....? 

    You can scan with the filter accept list (https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.3.0/zephyr/connectivity/bluetooth/api/gap.html#c.bt_le_filter_accept_list_add). With a filter accept list, the controller will only scan for devices in the list and ignore the rest. You can load the list with addresses from the bond table.

    I tested this with the central_uart sample by adding the following changes:

    And it seemed to work. But it needs more review and testing to ensure it covers all scenarios. The accept list will for instance need to be updated when bonds are removed. I did not implement that.

    Zephyr includes a sample to demonstrate how the filter accept list can be used which you can use as a reference.  https://github.com/nrfconnect/sdk-zephyr/tree/main/samples/bluetooth/peripheral_accept_list. But note that it is for the peripheral role, so there will be some slight differences in the implementation. 

    Best regards,

    Vidar

  • Hello Vidar, thanks for your informations!
    I tried and implemented a scenario different than your example, using your suggestions on zephyr example on peripheral. 
    Using Peripheral accept list, I implemented a targeted advertise, so if there's a bond, the device is adv only at that central, otherwise it has no address list adv.

    This seems to be working now, and I'm trying to move in that direction.
    Thanks a lot for your support!

    Enrico

  • Sorry for Re-Opening the ticket  ...

    I have a problem with the implementation.
    The first time, everything works properly.

    Peripheral just flashed, empty.
    Central just flashed, empty.

    Well, after the pairing, as suggested in the example, I soft-reboot the peripheral device in order to start advertising only to my whitelisted device, i.e. the just bonded central.

    BUT, after restarting the peripheral, the central seems not able to initiate the connection again.

    In fact, during the re-connection, the central device on "connected" callback, gives the error:

    BT_HCI_ERR_UNKNOWN_CONN_ID

    And, as all examples shows, this lead to a failure on connection establishment.

    So, where's the problem ?


    Note: using iOS nRF App, it seems that the re-connection works... after reboot I can see the device in the list, click CONNECT and that's okay.

    I imagine problem is on central side... is there something to enable, to catch this re-connection after bonding ?

    Thanks......

     
  • Hi,

    It sounds like only the address of the iPhone is added to the filter accept list. Are you logging the addresses that are being added to the list as here: https://github.com/nrfconnect/sdk-zephyr/blob/main/samples/bluetooth/peripheral_accept_list/src/main.c#L105 ?

    Note that you must increase CONFIG_BT_MAX_PAIRED to store multiple bonds.

Reply Children

  • Hello Vidar, 

    yesterday I go inside every kconf activated, and I removed:

    CONFIG_BT_SIGNING=y
    CONFIG_BT_PRIVACY=y

    that were activated on the peripheral device.
    They seems to cause the problem.

    Without this settings, the connection seems stable.
    Maybe the generation of new random mac for the device makes harder re-connection.