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

periodic configuration of Advertisement and sleep

I want advertise the peripheral  periodically only. i implement the logic it is working fine.but my doubt is once i connected to connected to central device advertise is no need.but after stopping the advertisement the device is disconnecting automatically.please can you explain the reason for disconnection.

here i am attaching the code

if(adv_start_time>ADVERTISE_START_INTERVAL)
{
if(adv_start_time==(ADVERTISE_START_INTERVAL+1))
{

err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);
}
adv_stop_time++;
}

if(adv_stop_time==ADVERTISE_STOP_INTERVAL)
{
advertising_stop();
adv_stop_time=0;
adv_start_time=0;
}

  • Hi,

    It is impossible to say what is the disconnect reason based only on the piece of code you attached.

    What board (development kit) are you using?

    What version of the SDK are you using?

    Have you built the project from an SDK example project? Which one?

    It may be that the board resets, because of APP_ERROR_CHECK() detecting an error. This is very useful, as it lets you debug and figure out what line and what error code you get. Have a look at My device is freezing and restarting. File, line and error code would be very useful for figuring out what happens.

    Can you provide a log from running the program? (In SDK 12 or later you enable logging in sdk_config.h, it is the NRF_LOG_ENABLED setting. You then choose either the NRF_LOG_BACKEND_SERIAL_USES_UART or the NRF_LOG_BACKEND_SERIAL_USES_RTT, depending on if you want to log over UART or over RTT. See for instance this thread.)

    If possible, can you provide a sniffer log?

    I highly recommend using the Advertising Module for advertising. It will automatically cycle through the enabled advertising modes and then end up in "idle" which means no advertising. You can also set a mode to never time out, which means you will stay in that advertising mode indefinitely. (Or, in the case of connectable advertising, it will stop advertising when it connects.) Have a look at any BLE peripheral example in the SDK to see usage examples of the Advertising Module.

    Regards,
    Terje

Related