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

sd_ble_gap_adv_stop()

I have a beacon type running firmware. My system should start advertising when I press button A. and then stop when I press button B. So here is the scenerio:

Scene 1:Press button A(ok), press button B(error/restart) Scene 2:Press button A(ok), press button B(ok), press button A(error/restart)

I read a lot of these in the forums but cannot find how to properly resolved the issue. Like, stopping the advertisment when it is not advertising, but, how should I know if its in advertising state or not.

Is there any other way to implement this or other function to call. Thank you very much.

Parents
  • Well if you write your FW you should know in what state your application is. You can have stupid bool variable saying "advertising ON/OFF". Because it's application FW which is implementing GAP profiles it's kind of logical it must track its state. Anyway even for lazy developers there is a option: simply get status code returned by Soft Device and if it's NRF_ERROR_INVALID_STATE then you probably weren't advertising and you can try to ignore it (but it's not advised to ignore API documentation so please read it;) Indeed you can get this error even in different situations (like when SD isn't properly initialized/enabled) but that's kind of obvious... and if you ignore keeping track about internal states of your app it's good chance you will have bigger problems and dead-locks then this;)

  • as you can see in my example right. I don't need a stupid bool variable to monitor advertising. I press A button, check NRF connect if advertising(adv=ok), then I press button B to call sd_ble_gap_adv_stop(). But the function never returns any, from there it will restart my mcu.

Reply Children
No Data
Related