nRF52840 as Central and Peripheral concurrent

Developing nRF52840-based devices that needs to act as both BLE Central and Peripheral.  

I've seen examples for the Multi-Link Multi-Role aggregate , the NUS Multilink Star typology, and the Heart Rate Relay.  They all seem to dedicate a single node/device to act as the Central/Peripheral and then have other Peripherals (only) or Centrals (only) connecting to them. 

The idea for my final implementation is to have x number of devices receive commands from a mobile app (similar to how the aggregate example demonstrates).  Just imagine something simple like a solitary LED changing color.  I'd like to let the user pick from a list which light to blink.  I would like to have all my devices be Multi-Role (both Central and Peripherals) and be able to connect to one another to distribute the commands (because the phone can only connect to one peripheral at a time). 

I will not know how many devices the end user will have, it could be two, it could be a hundred. And there would be no dedicated central other than the phone.

I understand the connection limitation of one nRF52840 is 20, however it's also mentioned that each of those 20 could connect to 20 more, and so on and so on. So that one device could connect to 20 and each of those 20 to 20 more ( creating a small network). 

So my questions are: 

  1. Could all my devices be both Central and Peripheral? 
    1. Meaning they'd share the same base code, same device name, same services, etc.
    2. Imagine the heart rate relay, only they are all acting as the relays, make sense?
  2. If this is possible, how do the devices determine who is central to what peripheral?
    1. If I'm looking at the aggregate example, it's listing in the mobile app all the available devices that are connected to the aggregate.
      1. So if I have two aggregate devices, who would be the primary central?
      2. And would they both be able to pass on their lists of devices to the mobile app?

It seems to me this should be rather simple, but I can't find an example that shows this being possible. 

Am I making this more complicated than it needs to be?

If this isn't clear, let me know so I can clarify. 

Thank you!

  • Hi Tai,

    The short answer is, it's possible by design, they made it so it functions this way.  And while it is diverse and flexible, the nRF52 programming seems to be equally confusing...lol. I completely understand your dilemma. 

    I think the first thing is to take a look at the sdk_config.h file included with the ble_aggregator example. You'll notice a section with this information..

    These settings control how many links each device will have. So, as you can see, the NRF_SDH_BLE_PERIPHERAL_LINK_COUNT is set to 1. That means the device will act as a peripheral to one central (aka phone, in this case). 

    The NRF_SDH_BLE_CENTRAL_LINK_COUNT is set to 16. That means the device will act as a central to 16 peripheral devices. 

    The NRF_SDH_BLE_TOTAL_LINK_COUNT is set to 17, which I think is pretty self explanatory. You just have to make sure you set this number correctly or it won't work.

    There is a limitation on the number of concurrent devices that can be connected. Part of that has to do with the amount of memory available.

    Next, I would probably take a look at the section in the main.c file ble_evt_hander , within the switch cases you'll find two you should take a closer look at.  BLE_GAP_EVT_CONNECTED  and BLE_GAP_EVT_ADV_REPORT.  

    BLE_GAP_EVT_CONNECTED shows code for both instances where the device acts as central and peripheral. 

    BLE_GAP_EVT_ADV_REPORT shows code for what to do with the information received from the (16) periperal devices . Specifically, within the on_adv_report() function.

    Also, worth looking at is the advertising_data_set() , which is the information your device will use, as it's role, as a peripheral to the phone.

    It's not a simple answer, the truth is, it requires studying the code in a bit more detail to understand "HOW" this is all done. Hopefully this helps point you in the right direction. Slight smile

  • Hi  I really appreciate this! I actually spent almost entire day yesterday to study more on this. Luckily, there is a tutorial for a central device. I feel more confident to work on this right now Joy. Btw, just tagged you in my post. Hope to receive any comments/suggestions for my approach and some bugs happening.

    In case you can't find it, I added the link of my post here. Looking forward to hearing from you!

    Option for better throughput with BLE multi-link/multi-role - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)

  • hey hi BLE Relay Example is Peripheral tx relay only how to relay tx to Peripheral

Related