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

Device Name set question

修改Device_Name.jpg

After programming, the device name cannot be changed. Is there any solution that can achieve? I know that I can change the paramter from the function in attached file. But I need the method can make me change the device name after programming. and the p_dev_name is need const parameter

  • Maybe like this?

    1. Create array in flash that will contain your device name like this.

    2. On power on set device name using sd_ble_gap_device_name_set() with this array.

    3. On receiving device name change command over your custom service characteristic store received string in your array in flash.

    4. Set device name using sd_ble_gap_device_name_set() with this array.

    UPD:

    Though best is just using pstorage to store your data and update it with array in RAM as you aren't restricted to use only const parameter, for example, this will work as well:

    #define DEVICE_NAME                        "My_device"
    
    uint8_t arr[sizeof(DEVICE_NAME)];
    strcpy((char *)arr, (const char *)DEVICE_NAME);
    
    err_code = sd_ble_gap_device_name_set(&sec_mode,
                                          (const uint8_t *)arr,
                                          strlen((char *)arr));
    APP_ERROR_CHECK(err_code);
    
  • In #3, how do you propose to write to your array in flash when it's declared as const?

  • You can do it with sd_flash_page_erase()/sd_flash_write() because the const array takes up the whole page (1024 bytes).

  • So you're going around the back of pstorage straight to the underlying flash write and you're using 1024 bytes for a device name that can only be 32 bytes long? There must be a better way.

  • Well, I did mention below in my answer that if you don't really need to use const in your program then you can use pstorage for better use of flash memory. But if you really need to use const, then I don't think there is another way to do it.

Related