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

  • Katie Newell said:
    Many thanks for your reply

    No problem at all, I am happy to help! :)

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

    Are you saying that you are able to see the device with nRF Connect for Desktop when you exclude the advertising update procedure, but not when it is included?
    That would be very strange indeed. Which device are you using as your nRF Connect for Desktop connectivity device? Keep in mind that if you for example use a nRF51 device as the connectivity device, it will not be able to see 2 Mbps PHY advertisements.

    Could you try with the example project from the blogpost I referenced in my previous comment, to see if you are able to run this, and see its changing advertisements?

    Best regards,
    Karl

  • I am using nRF52840 dongle with nRF Connect for Desktop. Can this be the issue?

    I already tried your example and it worked as expected - I could see the advertising data changing on the nRF Connect for Desktop. In fact, it's where I found out about updating the advertising data and started using it in my application. Very well done and explained post - congratulations for that.

    Kind regards

  • Katie Newell said:
    I am using nRF52840 dongle with nRF Connect for Desktop. Can this be the issue?

    Thank you for clarifying. This should be fine - the dongle will be able to pick up all advertisements, no problem. It is also good to hear that you have successfully run the example from the blogpost, we then know that we have to look closer at your custom application to identify the root of this issue.

    Is your intention that the advertising data should update only once - when the FAST advertising starts? The BLE_ADV_EVT_FAST will only happen; when FAST advertising first starts.
    Could you show me the rest of your advertising initialization code?

    Katie Newell said:
    Very well done and explained post - congratulations for that.

    I am very happy to hear that you found it helpful, thank you for saying so! :)

    Best regards,
    Karl

  • 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

Reply
  • 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

Children
Related