NRF52840 advertise start and stop manually in logic

Hi all,

I want to ON and OFF advertise manually

My code working steps 

1) (APP_ADV_DURATION 3000 ) after this seconds over  

2) It hits on_adv_evt() function in this function case :BLE_ADV_EVT_IDLE i use sd_ble_gap_adv_stop(m_advertising.adv_handle);

Till this point it's working properly

3) In uart_event_handle() function 

char buff[2];
char str_cmp[2]= "ON";
if ((data_array[index - 1] == '\n') || (data_array[index - 1] == '\r') || (index >= m_ble_nus_max_data_len))
{
      memmove(buff,data_array,2);
      if(buff == str_cmp)
      {
          int Val = memcmp(buff,str_cmp,2);
          if(Val == 0)
          {
               NRF_LOG_INFO("ON\n");
               ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
               // ble_advertising_restart_without_whitelist(&m_advertising);
          }
      else
      {
             NRF_LOG_INFO("OFF\n");
         
       }
....
}
4) My Doubt is after 2nd Point hits 3rd Point will work or not
 
Otherwise suggest me how to advertise manually using uart_event_handle() function or any Idea
  • Hi,

    If you want to due unlimited advertising duration, set APP_ADV_DURATION to 0 

    And make sure you use General Discoverable Mode. i.e. in advertising_init() you have this:

    init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    Then it will not time-out and stop.
    And if you want to stop it manually,  try using sd_ble_gap_adv_stop()
Related