This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to advertise for less than one second with nrf51422

I would like to ask how to make advertisements which are less than one second. In my application, i need to scan for devices, when i find my specific device, i start to advertise with specific data. I know that i can advertise for 1 second by setting APP_ADV_TIMEOUT_IN_SECONDS = 1. Then im scanning, advertising for one second, then scanning again and so on and this application is working without any problems. But i want to make advertising intervals shorter. Lets say 150ms, 200ms or 250ms. What is the best way to achieve this?

Thank you in advance,

Regards.

  • Advertising timeout controls how long you advertise before stopping, the advertising interval controls how long between advertising events. If you want to advertise repeatedly for an interval less than 1 second, set the advertising timeout to zero and the interval to your sub-second interval. It becomes a bit more cumbersome if you only want to emit one advertisement before stopping, then you would probably need to use the radio notification feature so you could stop advertising after the first advertising event.

    Its tough to give you a more specific answer without going into a ton of detail without knowing exactly what advertising pattern you are attempting to achieve.

  • I'll accept your answer, but before that could you tell me an answer to this question then: Lets say im advertising each 100ms, and after 400ms or 4 advertising events i want to stop. Obviously then, i set advertising timeout to zero. So is there any callback which gets triggered when advertising event happens? I mean, how do i know that advertising event already happened? Or i should use radio notifications and make some counter value which i increment every time radio event happens, and when counter reaches some value (4 in this case), i just stop the advertising?

  • Hi, I am no aware of a event that is returned every time an advertising event occurs. There may be one, but I didn't find one in my quick look around. You can use radio notifications for sure as you should get one prior to each advertising event. You could also just set a 400 mS timer and use that to call the stop advertising function as well. You'd probably want to make the timer a little longer than 400 mS just to make sure the last advertisement got out.

  • You should be able to call sd_ble_gap_adv_stop() to stop advertising after less than one second

Related