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

ble_advertising_advdata_update stops device from advertising

Hi Nordic Team,

I am using ble_advertising_advdata_update() to update some of the advertising data. I am doing every time the device is asked to advertise. In my code I do at the event 'BLE_ADV_EVT_FAST' in the advertising events handler. See below my code.

The issue I am facing is when I include the adv_data_update() to the code, the device doesn't advertise. When it's not there, the device advertises. 

Is this expected? Am I doing something wrong?

I am using SDK 17.0.2 and nRF Connect Desktop to see and connect to my device.

Many thanks

/* Code */

1/ advertising events handler

static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
  ret_code_t err_code;

  switch (ble_adv_evt)
  {
  case BLE_ADV_EVT_FAST:
  {
    NRF_LOG_INFO("start - advertising.");
    adv_data_update();
    break;
  }
  case BLE_ADV_EVT_IDLE:
  {
    NRF_LOG_INFO("stop - advertising.");
    break;
  }
  default:
    break;
  }
  NRF_LOG_FLUSH();
}

2/ advertising data update function

void adv_data_update(void)
{
    ret_code_t                  err_code;
    ble_advdata_manuf_data_t    manuf_data;

    new_advdata.p_manuf_specific_data = &manuf_data;

    NRF_LOG_INFO("Updating advertising data!");
    
    manuf_data.company_identifier = APP_COMPANY_IDENTIFIER;

    manuf_data.data.p_data = (uint8_t *)&adv_data;
    manuf_data.data.size = sizeof(adv_data);
    
    err_code = ble_advertising_advdata_update(&m_advertising, &new_advdata, NULL);
    APP_ERROR_CHECK(err_code);  
  

    NRF_LOG_INFO("Advertising data updated!");
    NRF_LOG_FLUSH();
}

Parents
  • Hello,

    Thank you for your patience with this. The summer holidays have begun here in Norway, and DevZone is therefore operating with reduced staff for the time being. Sorry for any inconvenience this might cause.

    The issue I am facing is when I include the adv_data_update() to the code, the device doesn't advertise. When it's not there, the device advertises. 

    Do you get any error when this code runs?
    Do you see any other strange or unexpected behavior when this code section executes?

    Please see this blogpost about how to use the BLE Advertising library to dynamically update your advertising data.

    Best regards,
    Karl

  • Hi Karl

    Many thanks for your reply

    No problem at all. Summer holidays here in UK as well :) 

    I didn't get any error while compiling or running the code. The code executes as expected.

    The other strange thing I see is the App on my phone can see the device advertising, connects to it and everything works ok but not with nRF Connect Desktop.  

    Kind regards

  • Hi Karl

    Yes that's intentional. To give you a bit of context, in my application, the MCU goes into sleep mode and wakes under some conditions to advertise. My purpose here is to update the advertising data once at every advertisement. 

    Sure, see below my advertising_init()

    Many thanks

    static void advertising_init(void)
    {
      ret_code_t err_code;
      ble_advertising_init_t init;
    
      memset(&init, 0, sizeof(init));
    
      //ToDo
      ble_advdata_manuf_data_t                  manuf_data; //Variable to hold manufacturer specific data
      uint8_t data[10]                          = {0x64, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //Vertex data to advertise
    
      manuf_data.company_identifier             = APP_COMPANY_IDENTIFIER; //Nordics company ID
      manuf_data.data.p_data                    = data;
      manuf_data.data.size                      = sizeof(data);
      init.advdata.p_manuf_specific_data = &manuf_data;
    
      init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
      init.advdata.include_appearance = true;
      init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
    
      advertising_config_get(&init.config);
    
      init.config.ble_adv_fast_enabled = true;
      init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
      init.config.ble_adv_fast_timeout = APP_ADV_DURATION;
    
      init.evt_handler = on_adv_evt;
    
      err_code = ble_advertising_init(&m_advertising, &init);
      APP_ERROR_CHECK(err_code);
    
      ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    }

  • Thank you for the context - this is helpful for me to know!

    Katie Newell said:
    My purpose here is to update the advertising data once at every advertisement. 

    I might not be understanding you correctly here, but just to make sure I will mention that the BLE_ADV_EVT_FAST event only happens once, so the advertising data will be the same for all packets sent until the device stops advertising and goes to sleep again. If you intend for the advertising packets to be different every time a new packet is sent, you should use Radio Notifications to update the contents of the packet prior to the advertising radio event (or directly following the previous radio event).

    If you intend to keep the same advertising packet for the entire duration of the advertising (until the device goes to sleep again, waiting to restart advertising), then you do perhaps not need to 'update' the advertising data, since you will be starting the advertising anew every time you wake up, and keep the same data for the entire duration of the wakeup.

    Katie Newell said:
    the MCU goes into sleep mode

    Could you confirm whether this is SYSTEM ON sleep, or SYSTEM OFF sleep you are referring to? If it is SYSTEM OFF you will need to reinitialize the advertising, like you are already doing in advertising_init, and if it is SYSTEM ON you will need to call ble_adv_start(FAST) as part of the wake-up interrupt (this will also cause advertising to start and potentially advertise some 'old' advertising data, before the data is updated, since the FAST_STARTED event is generated _after_ advertising has started).

    Best regards,
    Karl

  • Hi Karl

    This is my intention as you descried below

    "If you intend to keep the same advertising packet for the entire duration of the advertising (until the device goes to sleep again, waiting to restart advertising), then you do perhaps not need to 'update' the advertising data, since you will be starting the advertising anew every time you wake up, and keep the same data for the entire duration of the wakeup."

    I am not sure I understand when you said "...then you do perhaps not need to 'update' the advertising data, since you will be starting the advertising anew every time you wake up..."

    My advertising data is dynamic - such as battery level -  so I need to update it every time I wake up. 

    The advertising data is updated in advertising_init which is executed at the start of my program in the main function and not every time I wake up. If I did execute advertising_init every time I wake up then I get ASSERTION FAILED error an the program crashes. That's why I am using advertising data update function every time I wake up.

    The other strange thing is that the App nRF Toolbox can see my device. Only nRF connect doesn't see it.

    Would you be able to test this on your side?

    Many thanks

  • Hi Karl

    Actually no other central can see my device advertising other than my phone. When I include the update advertising data function, my device advertises but cannot be seen by any other device - expect my phone. Do you have any idea why this happening? 

    When I remove the update data function, my device can be seen. 

    Please advise. I am not sure I can use the update data function or maybe I am using it in the wrong place. 

    Many thanks for your help in advance

  • Hi Karl, 

    Would you be able to give me a feedback on this please? 

    I am stuck - I can't update the advertising data. 

    Many thanks for your support

Reply Children
No Data
Related