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

Setting Bluetooth Device Name in Zephyr

Using Zephyr, I'm looking to configure the BLE name of my devices to use the serial number they are provisioned with.  

To this end there is the API "bt_set_name" that seems like it should do it, but I have not yet found anyway to get it to actually change the name.  The Device always advertises with whatever CONFIG_BT_DEVICE_NAME is set to.

Has anyone successfully done this with Zephyr?

Thank you so much for your help!

Parents
  • You can set the device name in your code by calling "bt_set_name" function, after when Bluetooth has enabled but before when advertisement has started.

    Also it is necessary to enable dynamic name capability in the project configuration in addition to add BT_LE_ADV_OPT_USE_NAME to  bt_le_adv_param variable.

    Add these options to prfj.conf file:

    ....
    
    # Enable Dynamic name modification
    CONFIG_BT_DEVICE_NAME_DYNAMIC=y
    # Maximum chcaracter of the device name
    # (Range: 2 to 248)
    CONFIG_BT_DEVICE_NAME_MAX=30

    and call bt_set_name after when bt has enabled but advertisement has not started

    main.c

    void main(void)
    {
        struct bt_le_adv_param param;
        ...
        bt_enable(NULL);
        ...
        bt_set_name("new name");
        ...
        param.options = BT_LE_ADV_OPT_USE_NAME;
        ...
        bt_le_ext_adv_create(&param, NULL, &adv_set);
        bt_le_per_adv_start(adv_set);
        
    }

Reply
  • You can set the device name in your code by calling "bt_set_name" function, after when Bluetooth has enabled but before when advertisement has started.

    Also it is necessary to enable dynamic name capability in the project configuration in addition to add BT_LE_ADV_OPT_USE_NAME to  bt_le_adv_param variable.

    Add these options to prfj.conf file:

    ....
    
    # Enable Dynamic name modification
    CONFIG_BT_DEVICE_NAME_DYNAMIC=y
    # Maximum chcaracter of the device name
    # (Range: 2 to 248)
    CONFIG_BT_DEVICE_NAME_MAX=30

    and call bt_set_name after when bt has enabled but advertisement has not started

    main.c

    void main(void)
    {
        struct bt_le_adv_param param;
        ...
        bt_enable(NULL);
        ...
        bt_set_name("new name");
        ...
        param.options = BT_LE_ADV_OPT_USE_NAME;
        ...
        bt_le_ext_adv_create(&param, NULL, &adv_set);
        bt_le_per_adv_start(adv_set);
        
    }

Children
No Data
Related