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

Set a name in beacon example SDK 12

Hey guys,

I have followed this tutorial that shows how to modify advertising data, and more particularly the name.

What I want to do is set a name in the beacon example of the SKD 12. With this example, nRF Connect sees my device as "N/A". So here is what I have done so far:

I have defined the device name :

#define DEVICE_NAME                      "test"

As there is no "gap_params_init()" in this example, I have tried to send only the name in the softdevice with those lines between "ble_stack_init()" and "advertising_init()":

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));

Finally, I have changed one line in "advertising_init()", from :

advdata.name_type             = BLE_ADVDATA_NO_NAME;

To :

advdata.name_type             = BLE_ADVDATA_FULL_NAME;

This last change give me an error (12) when "ble_advdata_set" is executed. I have found that error 12 is NRF_ERROR_DATA_SIZE.

So I have tried to increase APP_ADV_DATA_LENGTH from 0x15 to 0x19 ( 4 bytes of "test") but I get the same error.

Can someone help me to find what I am missing or what I am doing wrong?

Thanks for your help!

Parents
  • Hi,

    In the beacon example the advertising data packet is already filled up with other data, so there is not enough room for the device name. As explained in the tutorial, an advertising packet can consist of no more than 31 bytes. You are therefore getting the error NRF_ERROR_DATA_SIZE.

    Note that Beacons typically don't have a name, because there is little room left in the advertise packet after including the beacon payload. Beacons usually signal their intent and meaning by the URL or ID that they contain, and don't really need a local name.

    But, you can put the device name into the scan response packet like this:

    static void advertising_init(void)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
        ble_advdata_t srdata;
        uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
    
        ble_advdata_manuf_data_t manuf_specific_data;
    
        manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
    
    #if defined(USE_UICR_FOR_MAJ_MIN_VALUES)
        // If USE_UICR_FOR_MAJ_MIN_VALUES is defined, the major and minor values will be read from the
        // UICR instead of using the default values. The major and minor values obtained from the UICR
        // are encoded into advertising data in big endian order (MSB First).
        // To set the UICR used by this example to a desired value, write to the address 0x10001080
        // using the nrfjprog tool. The command to be used is as follows.
        // nrfjprog --snr <Segger-chip-Serial-Number> --memwr 0x10001080 --val <your major/minor value>
        // For example, for a major value and minor value of 0xabcd and 0x0102 respectively, the
        // the following command should be used.
        // nrfjprog --snr <Segger-chip-Serial-Number> --memwr 0x10001080 --val 0xabcd0102
        uint16_t major_value = ((*(uint32_t *)UICR_ADDRESS) & 0xFFFF0000) >> 16;
        uint16_t minor_value = ((*(uint32_t *)UICR_ADDRESS) & 0x0000FFFF);
    
        uint8_t index = MAJ_VAL_OFFSET_IN_BEACON_INFO;
    
        m_beacon_info[index++] = MSB_16(major_value);
        m_beacon_info[index++] = LSB_16(major_value);
    
        m_beacon_info[index++] = MSB_16(minor_value);
        m_beacon_info[index++] = LSB_16(minor_value);
    #endif
    
        manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info;
        manuf_specific_data.data.size   = APP_BEACON_INFO_LENGTH;
    
        // Build and set advertising data.
        memset(&advdata, 0, sizeof(advdata));    
        advdata.flags                 = flags;
        advdata.p_manuf_specific_data = &manuf_specific_data;
        
           
        // Build and set scan response data.
        memset(&srdata, 0, sizeof(srdata));
        srdata.name_type             = BLE_ADVDATA_FULL_NAME;
    
        err_code = ble_advdata_set(&advdata, &srdata);
        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_SCAN_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;
    }
    

    Note that I have made the beacon scannable by changing the type from BLE_GAP_ADV_TYPE_ADV_NONCONN_IND to BLE_GAP_ADV_TYPE_ADV_SCAN_IND, and that if you are making a iBeacon the iBeacon spec specifically states that ADV_NONCONN_IND must be used.

  • Thanks for your answer! I was trying to reduce packet by removing major, minor values and RSSI. I use this place now to send adc values. Maybe there is a better way. But like this and with your solution, all is working as expected!

Reply Children
No Data
Related