How can I make peripheral device name configurable?

Dear all

I am developing a BLE product, and would like to have a different device name for each unit like Product1, Product2 etc. when advertising, so user can identify each of them.

I noticed Device name in Generic Access service is read only, is there a way I can configure it differently?

Regards!

Ping

Parents Reply
  • Thank you for your contribution, Hieu

    My application requires a name change after it starts up, to attach a bit more id related information in the name. 

    It is a good idea that it starts with local device name - shorted version of like Product , and then attach a ID. so, it becomes ProductID later. In my application the ID is from host MCU via serial interface.

    I don't mind stop advertising and restart again later, my question is - do I define two set of ad data like below?  I might need to make the complete device name as a variable, I suppose? Do I advertise with both local name and complete device name? any examples please?

    #define DEVICE_NAME             CONFIG_BT_DEVICE_NAME
    #define 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),
    };
     

    Regards!

    Ping

Children
  • Hi Ping,

    Yes, what you are doing is one correct way of doing it. Just want to point out a few things to be careful about it:

    1. If you are not using the full name of your device in the advertisement, you should use the ad data flag BT_DATA_NAME_SHORTENED instead of BT_DATA_NAME_COMPLETE. Apparently it will still work, but it is improper.

    2. If you are already providing a Local Name data in your bt_data_ad array, don't set the bt_le_adv_param.option BT_LE_ADV_OPT_USE_NAME when creating advertisement set or starting advertisement.
      I did some quick experiments and both bt_le_ext_adv_set_data() and bt_le_adv_start() don't like it and will fail.

      (And as you might have guessed, one different way is the opposite BT_DATA_NAME_COMPLETE and just use the advertising option BT_LE_ADV_OPT_USE_NAME.)

    3. Remember to set the Kconfig CONFIG_BT_DEVICE_NAME_DYNAMIC appropriately

    If you want to discover different solutions, you can also try looking into Manufacturer Data and a custom app parsing data from it as well. Depends on your product design, it might be more suitable.

    Best regarsd,
    Hieu

  • Thank you, it works now, just don't think the last option(CONFIG_BT_DEVICE_NAME_DYNAMIC ) is necessary as I stop adv first and restart again after I got a full name with ID.

    One more question, I need to save the full device name with ID once it is received, so it stays over power cycles, how can I do that please?

    Regards!

    Ping

  • Hi Ping,

    Good to know that things are working. Also interesting to know that CONFIG_BT_DEVICE_NAME_DYNAMIC doesn't matter.
    Its name is very clear and it has always been on for me so I didn't check what happened if it is turned off. Interesting, I wonder what it is for then.

    Regarding saving over power cycles, you could refer to this recent Q&A:  RE: Recommended solution for persistent data storage in NCS . The question looks different at first but they are discussing exactly what you need over there.

    Best regards,
    Hieu

Related