This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unique BLE device name

Hi,

I am currently writing the firmware of one of our products that will be produced in mass market, and now my goal is to have a unique BLE device name for every sample. I try to use the DEVICEADDR register to generate a 16 bit number that will be concatenated to a string that will be the base of the device name. But for know, the code doesn't compile and I'm not even sure that I'm doing this the right way.

Here is my code I wrote in gap_params_int() function :

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

ble_gap_addr_t *p_addr;

sd_ble_gap_address_get(p_addr);

uint8_t* device_addr = (p_addr->addr + BLE_GAP_ADDR_LEN - 2);

const uint8_t* device_name = {*DEVICE_NAME, *device_addr};

err_code = sd_ble_gap_device_name_set(&sec_mode,
                                      device_name,
                                      strlen(device_name));
APP_ERROR_CHECK(err_code);

Here are the following errors :

'p_addr' is used uninitialized in this function [-Werror=uninitialized]

(near initialization for 'device_name') [-Werror]

excess elements in scalar initializer [-Werror]

initialization makes pointer from integer without a cast [-Werror]

pointer targets in passing argument 1 of 'strlen' differ in signedness [-Werror=pointer-sign]

Could you please tell me what am I doing wrong, or how to do what I am trying to do ?

PS : My target is an nRF51822 QFAC, I use SDK v11.0 and softdevice S130

Best regards,

Guillaume

Parents
  • If you want to add the Bluetooth address (or some bytes) at the end of the advertising name of your device, you should do something like this:

    #define DEVICE_NAME           "<name>"
    #define DEVICE_NAME_MAX_SIZE  18
    
    // Append the two MSB of the BLE address, for instance
    // - BLE address  = AB:CD:XX:XX:XX:XX
    // - BLE ADV name = <name> ABCD
    
    char device_name[DEVICE_NAME_MAX_SIZE];
    uint8_t name_size = strlen(DEVICE_NAME);
    
    memcpy(device_name, DEVICE_NAME, name_size);
    
    // Encode the BLE address as a String and set the advertising name
    sprintf(&device_name[name_size], " %X%X", addr.addr[BLE_GAP_ADDR_LEN - 1], addr.addr[BLE_GAP_ADDR_LEN - 2]);
    uint32_t errCode= sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *) device_name, name_size + 5);
    APP_ERROR_CHECK(errCode);
    

    You can use the sprintf function to format the advertising name as you like.

Reply
  • If you want to add the Bluetooth address (or some bytes) at the end of the advertising name of your device, you should do something like this:

    #define DEVICE_NAME           "<name>"
    #define DEVICE_NAME_MAX_SIZE  18
    
    // Append the two MSB of the BLE address, for instance
    // - BLE address  = AB:CD:XX:XX:XX:XX
    // - BLE ADV name = <name> ABCD
    
    char device_name[DEVICE_NAME_MAX_SIZE];
    uint8_t name_size = strlen(DEVICE_NAME);
    
    memcpy(device_name, DEVICE_NAME, name_size);
    
    // Encode the BLE address as a String and set the advertising name
    sprintf(&device_name[name_size], " %X%X", addr.addr[BLE_GAP_ADDR_LEN - 1], addr.addr[BLE_GAP_ADDR_LEN - 2]);
    uint32_t errCode= sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *) device_name, name_size + 5);
    APP_ERROR_CHECK(errCode);
    

    You can use the sprintf function to format the advertising name as you like.

Children
Related