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

  • 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

  • Hello again Katie22,

    I am terribly sorry that it has been so long since last you received a reply here!
    I have been out of office since last we spoke. I though another engineer was assigned to your ticket in my absence, my apologies.

    Katie Newell said:

    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. 

    Katie Newell said:
    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.

    Could you confirm for me whether you mean SYSTEM OFF or SYSTEM ON sleep from which the device is waking? In case of the former then the entire application will be ran from the start every time, in case of the latter this will not happen and you will need to call the advdata update function for each wakeup.

    Katie Newell said:

    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. 

    This sounds very strange. It would be very helpful to see a sniffer trace of the on-air BLE traffic here, to better understand what is going on.
    Are you familiar with the nRF Sniffer tool? It is a powerful tool to wield when developing with BLE.

    It would also be helpful to see a more complete version of your code, if possible. It is hard for me to comment on whether you are using the update function in the right place, without having seen a more complete version.

    I again apologize for the major delay in answers on this ticker.

    I look forward to resolving this issue together!

    Best regards,
    Karl

Reply
  • Hello again Katie22,

    I am terribly sorry that it has been so long since last you received a reply here!
    I have been out of office since last we spoke. I though another engineer was assigned to your ticket in my absence, my apologies.

    Katie Newell said:

    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. 

    Katie Newell said:
    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.

    Could you confirm for me whether you mean SYSTEM OFF or SYSTEM ON sleep from which the device is waking? In case of the former then the entire application will be ran from the start every time, in case of the latter this will not happen and you will need to call the advdata update function for each wakeup.

    Katie Newell said:

    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. 

    This sounds very strange. It would be very helpful to see a sniffer trace of the on-air BLE traffic here, to better understand what is going on.
    Are you familiar with the nRF Sniffer tool? It is a powerful tool to wield when developing with BLE.

    It would also be helpful to see a more complete version of your code, if possible. It is hard for me to comment on whether you are using the update function in the right place, without having seen a more complete version.

    I again apologize for the major delay in answers on this ticker.

    I look forward to resolving this issue together!

    Best regards,
    Karl

Children
No Data
Related