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

How to keep the routine running in mainloop for nRF51822

I am developing a project by employing nRF51822 and my code is based on ble_app_uart. I met an issue that if there is no device connects to nRF51800 in 3 minutes, the program will run out of mainloop(I assume it goes onto idle mode or sleep mode). I tried to change APP_ADV_TIMEOUT_IN_SECONDS to bigger (default value is 180), such as 300, but the program will hold on advertising_start() and cannot enter mainloop.

Anybody can help me for setting advertising timeout to no limit.

Thanks Alex Chen

  • Sounds like you are advertising in limited discovery mode where 180s timeout is max. Remove this flag and you should be able to use a bigger timeout value. You should also consider adding code that restarts advertising on the previous timeout. Quite often an application would do fast advertisement for a limited time, then change to a slower advertisement interval when advertising for an unlimited time. When the advertisement times out you will get a BLE_GAP_EVT_TIMEOUT, this is where you can start advertising again.

  • Most (all?) of the Nordic examples seem to just advertise for 3 minutes (180s) and then stop - so the first thing you have to do is to work out how to continue doing something useful after that timeout.

    In some (all?) cases, a timeout of zero specifies "advertise indefinitely"...

Related