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

How to set variable BLE device name

OS in development environment :Windows7
HARD :(Taiyo Yuden)EBSHSN Series Evaluation Board : Central / Peripherals
CPU :(Nordic) nRF52832 / ARMR Cortex-M4F 32 bit processor 28-pin Land Grid Array / 15GPIOs / SWD
Soft Ver:nRF5_SDK_15.2.0_9412b96

The device name received by the UART is stored in non-volatile memory. After that, “sd_ble_gap_device_name_set” tries to set as “BLE device name”,
but “sd_ble_gap_device_name_set” cannot set it.
Please tell me how to set.
Thank you.

Parents
  • If your name string is not a constant, it's not a problem. Just cast it to a const pointer and it works:

    void setGapDeviceName(char* name) {
        ble_gap_conn_sec_mode_t sec_mode;
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
        APP_ERROR_CHECK(sd_ble_gap_device_name_set(&sec_mode, (const uint8_t*)name, strlen(name)));
    }

    Mind that in order to make this name change actually work, you have to re-initialize advertising using ble_advertising_init as in the beginning of the program and start advertising using ble_advertising_stop.

    Also, if you are currently advertising, you firstly need to run ble_advertising_stop before reinitializing and restarting.

    Lastly, if you are currently connected to the central, you can't run any of these (for example, central sends you a new device name). Raise a flag, and when you receive BLE_ADV_EVT_FAST or whatever you use as the advertising start event, check the flag. If flag is raised, clear it and reinitialize the advertising.

Reply
  • If your name string is not a constant, it's not a problem. Just cast it to a const pointer and it works:

    void setGapDeviceName(char* name) {
        ble_gap_conn_sec_mode_t sec_mode;
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
        APP_ERROR_CHECK(sd_ble_gap_device_name_set(&sec_mode, (const uint8_t*)name, strlen(name)));
    }

    Mind that in order to make this name change actually work, you have to re-initialize advertising using ble_advertising_init as in the beginning of the program and start advertising using ble_advertising_stop.

    Also, if you are currently advertising, you firstly need to run ble_advertising_stop before reinitializing and restarting.

    Lastly, if you are currently connected to the central, you can't run any of these (for example, central sends you a new device name). Raise a flag, and when you receive BLE_ADV_EVT_FAST or whatever you use as the advertising start event, check the flag. If flag is raised, clear it and reinitialize the advertising.

Children
Related