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

ble_advertising_advdata_update() gives me an error

Hello, Second time in here, thank you so much for all the support so far!

I'm developing a Beacon BLE, I wanna be able to send data over Advertising or Scan response.
So I've developed the function bellow and I'm calling it in a timer timeout handler.

void updateAdvertising() {
  /* Declaration of Error Code */
  ret_code_t err_code;
  ble_advdata_t   advdata;

  uint8_t testData[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x11, 0x22};
  uint8_array_t data_array;  // Array for Service Data structure.

  data_array.p_data = (uint8_t *)testData;  // Pointer to the data to advertise.
  data_array.size = sizeof(testData);       // Size of the data to advertise.


  ble_advdata_service_data_t service_data;  // Structure to hold Service Data.
  service_data.service_uuid = CUSTOM_SERVICE_UUID;
  service_data.data = data_array;  // Array for service advertisement data.

  memset(&advdata, 0, sizeof(advdata));

  advdata.name_type = BLE_ADVDATA_NO_NAME;
  advdata.include_appearance = false;
  advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

  advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
  advdata.uuids_complete.p_uuids = &m_adv_uuids[0];

  advdata.p_service_data_array = &service_data;  // Pointer to Service Data structure.
  advdata.service_data_count = 1;

  //sd_ble_gap_adv_stop(m_adv_handle);

  err_code = ble_advertising_advdata_update(&m_advertising, &advdata, NULL);
  APP_ERROR_CHECK(err_code);
}

Problem is:
 <error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] at ../../../Advertising.c:143
PC at: 0x0002BC2F

it returns me that, I tried to pause the Advertisement and same result, I didn't try to pause the scan, but I believe it wont do much of a difference. 

  • Hi,

    Which SDK are you using?

    Referring to SDK 17, when calling ble_advertising_advdata_update() the NRF_ERROR_INVALID_STATE can come either from the function itself, if advertising is not enabled. See this snippet from the implementation:

        if (p_advertising->initialized == false)
        {
            return NRF_ERROR_INVALID_STATE;
        }

    I do not see enough of you code to see if that is the case, but based on the description I assume no. If not, the error comes from sd_ble_gap_adv_set_configure(), and from the API doc:

     * @retval ::NRF_ERROR_INVALID_STATE                   Invalid state to perform operation. Either:
     *                                                     - It is invalid to provide non-NULL advertising set parameters while advertising.
     *                                                     - It is invalid to provide the same data buffers while advertising. To update
     *                                                       advertising data, provide new advertising buffers.

    The first is not the case when using ble_advertising_advdata_update(), but the second could be a problem for older SDK's, but should not happen with SDK version >= 16.

  • That's Odd, I will triple check things here to ensure Advertising is working properly, thank you for the lessons.

    My SDK is actually version 160098a08e2 (I think it's 16 for short)

Related