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

nrf51 BLE DeviceName in Beacon app SDK10

Hello there,

I'm facing inconsistency across two nrf51 PCB boards in term of sending the device name. I'm running the same exact code on both. One is advertising the device name but the other on is not (it appears as N/A on the nerf Connect app). I'm using SDK10 with 110 soft device. 

In the code, I'm sending 20 bytes in the advertisement here is my setup code 

static void advertising_init(void)

{   uint32_t      err_code;
    ble_advdata_t advdata;
    ble_advdata_manuf_data_t manuf_specific_data;
     //an advertising packet can consist of no more than 31 bytes! a header of 2 bytes (length and type) for each field in the advertising packet (appearance, name, service UUID, and so on).
    
    // Build advertising data struct.
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type = BLE_ADVDATA_NO_NAME; 
 
    // Load user data into manufacturer struct -- Currently, can take 24 bytes max instead of 29
    manuf_specific_data.data.p_data = (uint8_t *) m_rx_buf;
    manuf_specific_data.data.size   = BUF_SIZE;
    
    
    advdata.p_manuf_specific_data = &manuf_specific_data;
    advdata.include_appearance    = false; // False to free additional 4 bytes of space. 2 for the appearance characteristic and 2 for its header
    advdata.flags                 = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; //3 bytes 1 for the flag and two for its header
     advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
     advdata.uuids_complete.p_uuids  = m_adv_uuids;


    
    err_code = ble_advdata_set(&advdata, NULL);
    APP_ERROR_CHECK(err_code);

    // Initialize advertising parameters (used when starting advertising).
    memset(&m_adv_params, 0, sizeof(m_adv_params));

    m_adv_params.type        = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
    m_adv_params.p_peer_addr = NULL;                // Undirected advertisement.
    m_adv_params.fp          = BLE_GAP_ADV_FP_ANY;
    m_adv_params.interval    = NON_CONNECTABLE_ADV_INTERVAL;
    m_adv_params.timeout     = APP_CFG_NON_CONN_ADV_TIMEOUT;

    // Set the Advertising device name
    ble_gap_conn_sec_mode_t sec_mode;

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)DEVICE_NAME, strlen(DEVICE_NAME));
}

here is what I received on nerf Connect app from device 1 (showing the device Name):

Here is what I received on nerf Connect from device 2(showing N/A device Name): Note there is "Optek" word in the manufacture data  which I don't know what does it mean and why it is showing ?

any idea why the device name appears as N/A when using one nrf51 board but with other nrf51 the device name is been advertise where the same code is running on both nrf devices?

I appreciate your help.

Parents
  • Thanks for getting back to me Vidar.

    I was thinking that might be the reason (my phone is remembering the device when I used the connection code not the beacon code). So. I restart my phone and reinstall the nerf Connect app but still is showing the name. When I used other phone the "Solar" name is replaced by "N/A". So the issue is that my phone is remembering the device name.

    Thanks for pointing that out. 

    I have another question about the advertisement packet length. I'm trying to send 20 bytes in the advertisement along with the device name is that possible?

  • Maybe the phone is bonded with the device? In that case, you may go the phone's bluetooth setting and remove/forget the device.

    aalsubhi said:
    I have another question about the advertisement packet length. I'm trying to send 20 bytes in the advertisement along with the device name is that possible?

     Yes, as long as the encoded payload doesn't exceed 31 bytes. But I'm noticing from your code snippet that you're setting the device name (i.e. calling sd_ble_gap_device_name_set()) after encoding the advertising payload. I think you must do it before if you want the name to be included.

  • Thanks Vidar. It works now and showing the device name!

  • how do I attached scan response in the advertisement to send more data (more than 31 bytes) in non connectable mode?

    Here is my attempt , but the issue is showing the device as connectable. for my application the device should be non connectable. here is my advertisement inclination function :

    static void advertising_init(void)
    
    {   uint32_t      err_code;
        ble_advdata_t advdata;
        ble_advdata_manuf_data_t manuf_data_response;
        ble_advdata_manuf_data_t manuf_data;
        ble_advdata_t advdata_response;
        ble_adv_modes_config_t options;
        
         //an advertising packet can consist of no more than 31 bytes! a header of 2 bytes (length and type) for each field in the advertising packet (appearance, name, service UUID, and so on).
        uint8_t i,j =0;
        uint8_t data1[10], data2[21];
        
        for (i = 0; i < 10; i++)
        {
            data1[i] = m_rx_buf[i];
        
        }
    
        for (i =10; i < 31; i++)
        {
           
           data2[j] = m_rx_buf[i];
            j++;
        }
        // Build advertising data struct.
        memset(&advdata, 0, sizeof(advdata));
        //populate the adv packet
        manuf_data.data.p_data = (uint8_t *)data1;
        manuf_data.data.size   = sizeof(data1);
        advdata.name_type = BLE_ADVDATA_FULL_NAME;
        advdata.p_manuf_specific_data = &manuf_data;
        advdata.include_appearance    = false; // False to free additional 4 bytes of space. 2 for the appearance characteristic and 2 for its header
        advdata.flags                 = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
        ////uuid 3 bytes 1 for the flag and two for its header
        advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        advdata.uuids_complete.p_uuids  = m_adv_uuids;
        
        // Build advertising scan response struct.
        memset(&advdata_response, 0, sizeof(advdata_response));
        
        //prepare the scan response by loading the data on manufacture data
        manuf_data_response.data.p_data = (uint8_t *) data2;
        manuf_data_response.data.size   = sizeof(data2);
        
       //populate the scan response packet
        advdata_response.name_type = BLE_ADVDATA_NO_NAME;
        advdata_response.p_manuf_specific_data = &manuf_data_response;
        
       // Initialize advertising parameters (used when starting advertising).
        memset(&options, 0, sizeof(options));
    
        options.ble_adv_fast_enabled = true;
        options.ble_adv_fast_interval    = NON_CONNECTABLE_ADV_INTERVAL;
        options.ble_adv_fast_timeout     = APP_CFG_NON_CONN_ADV_TIMEOUT;
      
        ble_gap_conn_sec_mode_t sec_mode;
        
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    
        err_code = sd_ble_gap_device_name_set(&sec_mode,
                                              (const uint8_t *)DEVICE_NAME,
                                              strlen(DEVICE_NAME));
        APP_ERROR_CHECK(err_code);
        
       
        err_code = ble_advertising_init(&advdata, &advdata_response, &options, NULL, NULL);
        APP_ERROR_CHECK(err_code);
        
       
        
        
        
      
    }

    and here the advertisement start function:

    static void advertising_start(void)
    {
        uint32_t err_code;
        err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
        APP_ERROR_CHECK(err_code);
    
    }

    where should I specify that the device is not connectable?

    Thanks in advance.

  • It looks like the advertising module (ble_advertising.c) is always setting the BLE_GAP_ADV_TYPE_ADV_IND flag which indicate connectable advertising. As a test, please try to change that to BLE_GAP_ADV_TYPE_ADV_SCAN_IND.

Reply Children
No Data
Related