This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

BLE automatic connection to other BLE device

Hello

I'm using multiple nRF52840-dk (SDK17.1.0, Windows, Segger, S140).  

I'm trying to make BLE device(nRF52840-dk) that automatically connects to specific BLE device(nRF52840-dk) whenever it turns on without connecting to other devices.

Is there any great example/tutorial for this case?

After some search, in ble_app_hrs example I discovered that peer_manager_init() provides pairing and bonding, but I don't know how to utilize it. Can you tell me how to use it?

PS, Does pairing/bonding save anything else beside encryption key? Where/ which variable is the key saved at?

PSS I did found filter, but the central device will connect to any other peripheral

Parents
  • Hello,

    This is a bit up to your application. As you mentioned, the filters that are used can be used to search for particular devices. Either a specific UUID, an advertising name, or a BLE address.

    On the other side you have bonding (pairing = encryption, bonding = storing pairing data for later use). When you bond, you store bonding data for a particular device, so even if a similar device is nearby, it will only connect to the already bonded device. 

    I suggest that you look into the ble_app_hrs and ble_app_hrs_c examples if you are interrested in bonding. The data is stored by the peer manager in something called FDS (flash Data Storage), but it is not straight forward to see how it is done. The basic information that is stored is the address of the bonded device, and the keys that are used for encryption. This goes both ways, so if only one of the devices have the correct key, they will not be able to connect (security measure). The easiest way to bond two devices is to let them connect and bond like it is done in the ble_app_hrs_c example. Then they will look for one another the next time they are turned on.

    On the other hand, if you don't need the security of bonding, you can try to add a filter on the BLE address (this is unique on all devices), and only connect if the advertisement comes from the address that you are looking for.You can do this either by adding the address to a whitelist, like the hrs examples does, or by manually checking the advertising packet and connect if you see that it is coming from the correct device. You can add the BLE_GAP_EVT_ADV_REPORT event to the ble_evt_handler() in main.c to experiment and see what the advertisement looks like. It will trigger whenever you are scanning an advertisement packet.

    Best regards,

    Edvin

  • Thank you so much for the reply.

    Sorry for the change, I had to switch peripheral device into nRF52833-DK but I couldn't find ble_app_hrs example for the device. 

    Are there other example recommendation for  bonding and pairing with nRF52840-DK central and nRF52833-DK peripheral?

    Thank you in advance.

    PS I tried copy pasting ble_app_hrs example from nRF52840 S140 to other nRF52833 example. I could build it but couldn't run it (got hard fault error). hids keyboard and mouse seems great but I couldn't find good central example to connect it.

  • Sorry, it doesn't look like we have any other samples that does bonding as a central, and it doesn't look like we have that sample for the nRF52833. It should be possible to port it yourself. Just copy the project folder pca10056, name it pca10100, and look at the settings in the project. You would typically want to change everything that says 52840 to 52833, and adjust the memory areas. 

    I don't have time for that right now, because of low staffing due to the Christmas holidays, and I am leaving for holidays myself tomorrow. 

    Either try this approach, or you can start with an example that you imagine you would want to use in your final application, and implement the peer manager to that example, and perform the bonding like it is done in the ble_app_hrs_c example. 

    PS: We are very short staffed for the Christmas Holidays. I will go on vacation tomorrow, and I will be back in January.

    Best regards,

    Edvin

Reply
  • Sorry, it doesn't look like we have any other samples that does bonding as a central, and it doesn't look like we have that sample for the nRF52833. It should be possible to port it yourself. Just copy the project folder pca10056, name it pca10100, and look at the settings in the project. You would typically want to change everything that says 52840 to 52833, and adjust the memory areas. 

    I don't have time for that right now, because of low staffing due to the Christmas holidays, and I am leaving for holidays myself tomorrow. 

    Either try this approach, or you can start with an example that you imagine you would want to use in your final application, and implement the peer manager to that example, and perform the bonding like it is done in the ble_app_hrs_c example. 

    PS: We are very short staffed for the Christmas Holidays. I will go on vacation tomorrow, and I will be back in January.

    Best regards,

    Edvin

Children
  • Any tutorial for porting? Based on your answer, SW or application shouldn't be a issue.

    I tried modifying RAM and FLASH in SECTION PLACEMENT MACROS and change nRF52840 and pca10056 into nRF52833 and pca10100 in solution editor (</>). Building seems ok but running part is kinda stuck at "unknown fuction at 0x00000A60".

    Are there other things I should modify?

    Happy Holiday.

  • Hello.

    If it is stuck in 0x0A60, it is stuck in the hardfault handler. Probably related to some memory mapping or wrong device config. 

    I suggest that you start with a pca10100 project, and then add the peer manager like it is done in the ble_app_hrs_c example.

    If you really need to port the pca10056 to the pca10100, then open another pca10100 project, and make sure that the settings that you change look similar:

    I think those should cover it.

    Best regards,

    Edvin

  • Thanks, I managed to build successfully built hrs example on nRF52833-DK. (Just in case for other readers, RAM_START is a little different, error message will tell you where it starts)

    Problem is that I got stuck at peer_manager_init>pm_init>sm_init> nrf_ble_lesc_init>memset((void *) m_peer_keys, 0, sizeof(m_peer_keys));. (error does not display, I end up in HardFault_Handler.).

    One of our coworker managed to make it run, but eventually get into error during ble connection.(sorry for lack of error message, will try his code later)

    My question is: is LESC necessary for bonding?

    I came across cryptp CC310 in sdk_config.h and it says this crypto is only supported in nRF52840. Is CC310 necessary for LESC or bonding?

    Is PM_LESC_ENABLED and NRF_BLE_LESC_ENABLED related?

    Thanks

  • Hello,

    Yes. The RAM start and size depends on your BLE setup (number of services/characteristics, number of connections, MTU size, etc.) so you may need to change this in the future as well. Just monitor the log to see what it should be set to. 

    June20 said:
    My question is: is LESC necessary for bonding?

    No. You can use e.g. Just works.If you like. 

    June20 said:
    I came across cryptp CC310 in sdk_config.h and it says this crypto is only supported in nRF52840. Is CC310 necessary for LESC or bonding?

    No, you should disable it in sdk_config if you are using the nRF52833. You can use NRF_CRYPTO_BACKEND_MICRO_ECC_ENABLED instead of NRF_CRYPTO_BACKEND_CC310_ENABLED.

    June20 said:
    Is PM_LESC_ENABLED and NRF_BLE_LESC_ENABLED related?

    I believe that NRF_BLE_LESC_ENABLED needs to be set if you want to set PM_LESC_ENABLED. I haven't tested. Try to search for PM_LESC_ENABLED and NRF_BLE_LESC_ENABLED in the unmodified pca10056 example to see where it is used.

    Best regards,

    Edvin

  • Hello! Sorry for taking so long, I finally ported HRS into nRF52833 and successfully connected with HRS_C.

    We're trying to use bonding so that only one central(nRF52840 DK) and one peripheral(nRF52833 DK) connects to each other. 

    For example: we have many centrals (nRF52840 DK) and many peripherals (nRF5833 DK). Once Central_1 and Peripheral_1 is bonded, Central_1 cannot connect with Peripheral_2 or Central_2 cannot connect with Peripheral_1.

    What configuration should I touch/modify?

    I came across Central_Link_Count and Peripheral_Link_Count in sdk_config.h. Do they just mean how many central/peripheral they can connect/store or are there more? Should I put 1 each for both central and peripheral?

    Thanks

Related