Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

How to Interleave two different advertisement sets in nrf sdk 17.1.0 having different advertisement intervals that can change dynamically ?

I have two different advertisement sets with different advertisement data, both connectable, that I have to configure to have different advertisement intervals which can also change depending on some conditions. Suppose let the two advertisement sets be Set A and B. Set A needs to be advertised at 500 ms interval, which can change to 800 ms interval delay if no connection is made after 5 hours. Set B needs to advertise at 100 ms and interval will change to 3 sec after 1 day of inactivity. Earlier I was trying to implement this by using two different timers to advertise the two advertising sets, and update the timeout time of the timers accordingly if no connection is made.

I am using nrf sdk 17.1.0 that doesn't support Multiple advertising sets, hence this approach. Is this the correct way? Is there any better alternative to accomplish this?

Any help is appreciated. Thanks in advance!

  • As you write, the nRF5 SDK and SoftDevices only support a single advertising set, so the only way to mimmick this is to reconfigure the advertiser when switching between the sets. Using two separate timers like you describe seems not ideal to me as you risk both happening more or less at the same time, where you could get problems. At least you should probably use some form of syncronization mechanism to ensure that you don't get problems with this approach. Another posibility could be to use a single timer and keep track of the time since last event for both advertisiers, and calculate when to wake up next, and handle it that way. But as long as you find an approach that works for you that should be OK.

  • Another posibility could be to use a single timer and keep track of the time since last event for both advertisiers, and calculate when to wake up next, and handle it that way

    Could you elaborate more on this approach?

    Using two separate timers like you describe seems not ideal to me as you risk both happening more or less at the same time, where you could get problems.

    I might be wrong as well but If if two timers are up at the same time isn't their handlers executed sequentially in some form? Could you guide me more or elaborate the possible problems this approach might have?

  • arshi said:
    Could you elaborate more on this approach?

    You need to wake up at regular intervals for two conceptuall asyncroneous events that you can keep track of. Then, every time you wake up, you could calculate which of the two events happen next, and schedule a singel shot timer to wake you up at that event. Then redo the calculations (in principle this is how the app timer library works, configuring the RTC to wake up when the next of an arbitrary number of app timer instances times out).

    But the key point here is that this is entierly up to you, there are many ways you can do this, and there is not a single "correct" way. As long as what you do works for you, and you give it some thought so that there are not any corder cases you have not handled, it should be good.

    arshi said:
    I might be wrong as well but If if two timers are up at the same time isn't their handlers executed sequentially in some form?

    That is correct.

    arshi said:
    Could you guide me more or elaborate the possible problems this approach might have?

    You will have to first ocnfigure the advertiser, and then I assume you want to wait until the advertising packet has been sent. Probably by sleeping. And then it cold happen that the other timer expiers and you reconfigure the radio before the advertising packet has been sent. It is definetly something you can handle, but I just wanted to highlight that if you do not handle it, it may cause problems.

    PS: If you are still early in development I would consider migrating to the nRF Connect SDK.

Related