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

  • I'm using SDK 15.3 on a 52840 and this works on startup, no problem.

    Now suppose I want to change the name every couple of minutes?  I can set the name with this code but it's not changing on the adverts as far as I can see.  Must be missing something.

    This post ( How to change the device name?) says to issue a function call that doesn't exist in this version of SDK (the post is quite old) and I haven't figured out what the right one is in this version of SDK.  If I go back for an init using ble_advertising_init(), I get an 8 error code back.

Reply
  • I'm using SDK 15.3 on a 52840 and this works on startup, no problem.

    Now suppose I want to change the name every couple of minutes?  I can set the name with this code but it's not changing on the adverts as far as I can see.  Must be missing something.

    This post ( How to change the device name?) says to issue a function call that doesn't exist in this version of SDK (the post is quite old) and I haven't figured out what the right one is in this version of SDK.  If I go back for an init using ble_advertising_init(), I get an 8 error code back.

Children
No Data
Related