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

[nRF Connect SDK] How to change BT name

Target nRF52832(nrf52dk_nrf52832)
SDK NCS v1.9.1
Base source
1. C:\Users\user\ncs\v1.9.1\nrf\samples\bluetooth\peripheral_hids_keyboard
2. C:\Users\user\ncs\v1.9.1\nrf\samples\bluetooth\peripheral_hids_keyboard
My project require two mode(HID and NUS).


I received bt name via UART before call bt_enable(NULL);
but name information already defined at compile time.
static const struct bt_data sd[] = {
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};

I found good option and API but it did not work.
CONFIG_BT_DEVICE_NAME_DYNAMIC
bt_set_name("new name")

When do I call bt_set_name() ?
Can you please guide for me?

Parents
  • Thanks for updating.

    DEVICE_NAME is determined at compile time. What I'm asking you is how I can change ad[] variable in runtime.

    In my test, bt_set_name() did not work.

    I believe you have good solution.

  • DEVICE_NAME is determined at compile time.

    void main()
    {
        String DEVICE_NAME = "Uart name"; // this is for example only.
                                            You can determine this variable anywhere
        uint8_t DEVICE_NAME_LEN = (sizeof(DEVICE_NAME) - 1);
        
        static const struct bt_data ad[] = {
        	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
        	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
        };
        
        static const struct bt_data sd[] = {
        	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_NUS_VAL),
        };
        
        #define BT_LE_ADV_CONN_TEST BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE, \
                                                       adv_param_interval_min, \
                                                       adv_param_interval_max, NULL)
        
        err = bt_le_adv_start(BT_LE_ADV_CONN_TEST, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
        if (err) {
        	LOG_ERR("Advertising failed to start (err %d)", err);
        	return;
        }
    }

  • I want to use NEW name but not DEVICE_NAME.
    I'll receive new name via UART before bt_enable(). and I have to display new name

Reply Children
Related