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

How to set BLE device name based on device parameters

Dear Nordic,

we would like to set the BLE device name like this: "model" "serial number" (for example: "Model 024585").

The serial number is on a EEPROM, and the device name will have the same nave from the startup to the poweroff.

Following your example, the device name is a #define and sd_ble_gap_device_name_set() accepts only pointer to constant string, so please could you tell me how can I set a different device name based on custom serial number for each different device?

Thanks.

Parents
  • Hello,

    You need to prepare the string into a contiguous buffer before you pass it to sd_ble_gap_device_name_set(). It may look something like this:

    static void gap_params_init(void)
    {
        uint32_t err_code;
        char device_name_str[BLE_GAP_DEVNAME_DEFAULT_LEN];
        char name[] = "Model";
        char sn[]   = "024585"; // Serial number to be loaded from an ext. EEPROM  
        
        sprintf(device_name_str, "%s %s", name, sn);
    
        err_code = sd_ble_gap_device_name_set(&sec_mode,
                                              (const uint8_t *) device_name_str,
                                              strlen(device_name_str));
        APP_ERROR_CHECK(err_code);
            
        ...    

    Hope this helps. If anything is unclear, let me know.

    Best regards,

    Vidar

Reply
  • Hello,

    You need to prepare the string into a contiguous buffer before you pass it to sd_ble_gap_device_name_set(). It may look something like this:

    static void gap_params_init(void)
    {
        uint32_t err_code;
        char device_name_str[BLE_GAP_DEVNAME_DEFAULT_LEN];
        char name[] = "Model";
        char sn[]   = "024585"; // Serial number to be loaded from an ext. EEPROM  
        
        sprintf(device_name_str, "%s %s", name, sn);
    
        err_code = sd_ble_gap_device_name_set(&sec_mode,
                                              (const uint8_t *) device_name_str,
                                              strlen(device_name_str));
        APP_ERROR_CHECK(err_code);
            
        ...    

    Hope this helps. If anything is unclear, let me know.

    Best regards,

    Vidar

Children
Related