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

Help with understanding advertising choices

I am building a project that is based on the custom service example https://github.com/bjornspockeli/custom_ble_service_example but I don't like how it advertises in a way that only leaves 4 characters for my device name.

I grafted on the advertising method from ble_app_blinky as an alternate advertising function in my app (so I can go back and forth), and I get the full device name to show up in nRFConnect.  It doesn't work 100% yet--it won't launch into advertising again after a disconnect--but other than that think I like the result better.  Can someone help me understand why the blinky method leaves more space for the name, and what I am giving up by doing it that way?

Here's my "alt" advertising functions:

static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; /**< Advertising handle used to identify an advertising set. */
static uint8_t m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; /**< Buffer for storing an encoded advertising set. */
static uint8_t m_enc_scan_response_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; /**< Buffer for storing an encoded scan data. */

/**@brief Struct that contains pointers to the encoded advertising data. */
static ble_gap_adv_data_t m_adv_data =
{
.adv_data =
{
  .p_data = m_enc_advdata,
  .len = BLE_GAP_ADV_SET_DATA_SIZE_MAX
},
.scan_rsp_data =
{
  .p_data = m_enc_scan_response_data,
  .len = BLE_GAP_ADV_SET_DATA_SIZE_MAX

}
};

static void advertising_init_alt(void)
{
  ret_code_t err_code;
  ble_advdata_t advdata;
  ble_advdata_t srdata;

  ble_uuid_t adv_uuids[] = {{CUSTOM_SERVICE_UUID, m_cus.uuid_type}};

  // Build and set advertising data.
  memset(&advdata, 0, sizeof(advdata));

  advdata.name_type = BLE_ADVDATA_FULL_NAME;
  advdata.include_appearance = true;
  advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;


  memset(&srdata, 0, sizeof(srdata));
  srdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
  srdata.uuids_complete.p_uuids = adv_uuids;

  err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
  APP_ERROR_CHECK(err_code);

  err_code = ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len);
  APP_ERROR_CHECK(err_code);

  ble_gap_adv_params_t adv_params;

  // Set advertising parameters.
  memset(&adv_params, 0, sizeof(adv_params));

  adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
  adv_params.duration = APP_ADV_DURATION;
  adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
  adv_params.p_peer_addr = NULL;
  adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;
  adv_params.interval = APP_ADV_INTERVAL;

  err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
  APP_ERROR_CHECK(err_code);
}

static void advertising_start_alt(bool erase_bonds)
{
  ret_code_t err_code;

  if (erase_bonds == true)
  {
  delete_bonds();
  // Advertising is started by PM_EVT_PEERS_DELETED_SUCEEDED event
  }
  else
  { 

  err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
  APP_ERROR_CHECK(err_code);
  }
}

  • Hi Keith

    Have you added any additional services that take up space in the advertising packet? I just tried the custom service project myself and I'm able to see the full name without any problems. If you add additional service UUIDs to any examples that don't use scan response packets the name will be shortened if the advertising packet is filled with UUIDs, etc. Does that help to clear things up?

    I meant that it would be easier to implement the custom service(s) to the ble_app_blinky example, than adding the scan response packet implementation to the project you're already working on if the custom service(s) is the only thing you need from that project. The ble_app_blinky example still uses the ble_advertising module, so that is still the preferred module.

    Best regards,

    Simon

  • I finally figured out how to add a scan response packet with the ble_advertising module, so I just moved the entire device name by itself there.  I also made the appearance field optional, so I can steal those bytes back if I need them. It was actually a lot easier than I was making it out to be earlier.

    // remove the device name from the main advertising packet
    //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;
    
    init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.advdata.uuids_complete.p_uuids = m_adv_uuids;
    
    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;
    
    init.srdata.name_type = BLE_ADVDATA_FULL_NAME;
    #ifdef INCLUDE_APPEARANCE
    init.srdata.include_appearance = true;
    #endif
    
    err_code = ble_advertising_init(&m_advertising, &init);

Related