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
  • 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 ad[] = {
    BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
    BT_DATA(BT_DATA_NAME_COMPLETE, new_name, 32),
    };

    char new_name[32+1];

    memset(new_name, 0x0, sizeof(new_name));

    strcpy(new_name, "NewName");

    I could change  DEVICE_NAME to new_name. It worked.  But DEVICE_NAME_LEN should have 32.

    (I cannot use actual length)

    I'm afraid that wrong length made system halt.

    In addition, I don't have to use bt_set_name()

  • A regular advertisement packet can only hold 31 bytes of payload, which explains why your device name won't fit. For larger advertisement packets you could use the extended advertising feature introduced in Bluetooth 5: https://blog.nordicsemi.com/getconnected/bluetooth-5-advertising-extensions. But the drawback then is that the device will only be seen be scanners that supports extended scanning.

  • Hello.

    extended scan is not my problem.

    BT_DATA(BT_DATA_NAME_COMPLETE, new_name, 32),

    new_name can be "ABCD0001"(8) or "ABCDEF0001"(10) under 32Bytes in our product.

    BT_DATA(BT_DATA_NAME_COMPLETE, new_name, strlen(new_name)),

    -> I cannot have this usage due to compile error. so I open this case.

    I have no choice but to use fixed length(32) whatever new_name is.

    If I have new name as "RFR901", we can see NULL(\0\0\0...) in sniffer.

Reply
  • Hello.

    extended scan is not my problem.

    BT_DATA(BT_DATA_NAME_COMPLETE, new_name, 32),

    new_name can be "ABCD0001"(8) or "ABCDEF0001"(10) under 32Bytes in our product.

    BT_DATA(BT_DATA_NAME_COMPLETE, new_name, strlen(new_name)),

    -> I cannot have this usage due to compile error. so I open this case.

    I have no choice but to use fixed length(32) whatever new_name is.

    If I have new name as "RFR901", we can see NULL(\0\0\0...) in sniffer.

Children
Related