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

How to switch from connectable mode to beacon mode after disconnection

Currently I have been able to advertise and connect through debug app using nRF52 DK. My target is:

1. After the link is lost the bluetooth gets disconnected and at this time I want the DK to advertise in the beacon mode.

2. My purpose is that when some one with the app comes near I can send him the advertisement and the lost user can track the item.

How to implement this switch from connectable mode to beacon mode after disconnection

Parents Reply Children
  • Could you please let us know the SDK you are using

    I am currently using nRF5 SDK  and working on Proximity example from ble_pheripheral. Here I wanted to change the advertising to beacon mode when the app gets disconnected from the nRF52 DK. 

    I have a blog here about advertising that might be useful for you

    this blog is based on nRF-connect-SDK, which is not what I need. Can you give some example based on nRF5 SDK.  

    Have you designed how should the device return to connectable advertising after it start non-connectable advertising ? 

    Can you provide some example based on the same.

  • Hi Vishnu, 

    What you need to do is in advertising_init() you need to set: 

    init.config.ble_adv_on_disconnect_disabled=true. 

    This will disable the feature to start advertising automatically when disconnect. 

    Then after that you can write your own code in the BLE_GAP_EVT_DISCONNECTED event handler inside ble_evt_handler() function in main.c to start advertising  in beacon mode. I assume you are planning to do non-connectable advertising. Please follow what we have in the beacon example. 

  • I have tried implementing what you have suggested, but after disconnection it stops advertising rather than going to beacon advertising mode. I have added an advertising_beacon_init function and advertising_beacon_start function. Inside the BLE_GAP_EVT_DISCONNECTED I called the advertising_beacon_start function to start beacon mode. Is this the right way to proceed or is there anything I need to do extra.

  • Hi Vishnu,

    Please provide the code you used. I don't know what you have inside advertising_beacon_start (). 
    Please get familiar with how you can stop and re-start advertising. 

  • void advertising_beacon_start(bool erase_bonds)
    {
    
       if (erase_bonds == true)
        {
            delete_bonds();
            // Advertising is started by PM_EVT_PEERS_DELETED_SUCEEDED event
        }
        else
        {
            ret_code_t err_code;
    
          err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
          APP_ERROR_CHECK(err_code);
    
          err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
          APP_ERROR_CHECK(err_code); 
    
        }
        
    }

    This is the advertising_beacon_start function and this is called in BLE_GAP_EVT_DISCONNECTED as follows

     
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_DISCONNECTED:
                NRF_LOG_INFO("Disconnected.");
                
                 advertising_beacon_start(erase_bonds);
                 
                // LED indication will be changed when advertising starts.
                break;
    

    Please can you give a light on what is wrong here. If possible can you give a similiar example on how to tackle this problem. 

    Please get familiar with how you can stop and re-start advertising.

    can you give an example or link on how to familiarize with the same

Related