PSoC6: Change BLE advertisement name during run-time

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
srini_a
Level 3
Level 3
50 sign-ins 10 questions asked 10 replies posted

Hi Community,

I'm using PSoC 62 with LBEE5KL1DX (with CY4343W). The advertisement name comes from the Bluetooth Configurator's GAP settings. But because we will be having multiple devices with the same firmware, I'd like to change the advertisement name based on the MAC address or something unique dynamically during run-time. 

I can get the MAC id of the device using wiced_bt_dev_read_local_addr(). The advertisement name seems to be coming from wiced_bt_cfg_settings.device_name. When I call the wiced_bt_dev_read_local_addr() before I do the wiced_bt_stack_init(), the wiced_bt_dev_read_local_addr() function hangs; but when I call it after the stack init function, its OK, but it looks like it is too late to set the device name after the stack init is called.

Can someone suggest a proper way to change the advertisement name on startup instead of using the static name that comes from the gap settings page of the bluetooth configurator? 

Appreciate any advice/suggestions you can provide.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Dear @srini_a,

I am sorry for waiting.
Actually, I tried to make small changes with random number generated by TRNG (True Random Number Generator) that is supposed to give different name for each advertisement during run-time. Below screen shot is my trial using two PSoC 6 kits with CYW4343W. I load the same firmware on those devices.

2DevicesDiffName.jpg



















The key to make this working is in one of the variable that was mentioned on my previous post. That is "cy_bt_adv_packet_elem_1" array.
I attach sample code for you to see the changes. You can use any diff-tool to see the differences. Below snippets are example on changes in cycfg_gap.c and main.c.

SnipChangesInGAP.png

 

SnipChangesInMain.png

 

To check the full diffs, you may see directly on the files inside the attachment.
You can also modify the code to have longer name with more random digits.
WARNING: ANY MODIFICATION IN cycfg_gap.c WILL BE GONE (REPLACED) IF USING BT Configurator AGAIN.
I strongly suggest to save / backup any changes in that file!

If you still have any doubt(s), please feel free to ask.
Or if it is in another topic, you may also create new thread.

Best regards,
Muhammad Nanda

View solution in original post

8 Replies
AnjanaM_61
Moderator
Moderator
Moderator
5 comments on KBA First comment on KBA 5 questions asked

Hello @srini_a ,

You can use the BLE APIs only after stack init. 

What you can do is , set the desired name before the start advertisement API .  

Regards,

Anjana

0 Likes

Thank you for the reply. Can you please specify exactly which variable or API should I change before the start advertisement API?? I changed both wiced_bt_cfg_settings.device_name and app_gap_device_name. I'm using CySmart app(iOS), In the BLE devices list, it still shows the name configured through the BLE Configurator, but, interestingly, when I connect to this device, I briefly see "Connecting <updated name>" and connects to it; I would like it to show the updated name in the list of BLE devices in the CYSmart app.  So, looks like there are still remnants of the original name that I can't seem to figure out a way to update it during run-time. Please advise.

0 Likes
MuhammadNanda_K
Moderator
Moderator
Moderator
250 sign-ins 250 replies posted 50 likes received

Dear @srini_a,

Are you still working on this project ?
I have working on this query recently.

To change the advertising name, you may look in GeneratedSource/ folder. Please kindly try to change in below files:

  • "cy_bt_adv_packet_elem_1" array in cycfg_gap.c,
  • ".len" for complete local name in cycfg_gap.c,
  • "app_gap_device_name" array in cycfg_gatt_db.c,
  • "maxlen" and "curlen" of HDLC_GAP_DEVICE_NAME_VALUE in cycfg_gatt_db.c,
  • "app_gap_device_name_len" in cycfg_gatt_db.c and cycfg_gatt_db.h.

Please BE CAREFUL that you MUST remove "const" if you find it, in any of the mentioned files.

If you still have doubt(s), please feel free to ask
or if in another topic, you may also create new thread.

Thank you and regards,
Muhammad Nanda


0 Likes

Thanks for your response; but you misunderstood my question. I wanted to change the advertisement name during run-time; not by changing the static values in the files.

 

Regards,

Srini

0 Likes
lock attach
Attachments are accessible only for community members.

Dear @srini_a,

I am sorry for waiting.
Actually, I tried to make small changes with random number generated by TRNG (True Random Number Generator) that is supposed to give different name for each advertisement during run-time. Below screen shot is my trial using two PSoC 6 kits with CYW4343W. I load the same firmware on those devices.

2DevicesDiffName.jpg



















The key to make this working is in one of the variable that was mentioned on my previous post. That is "cy_bt_adv_packet_elem_1" array.
I attach sample code for you to see the changes. You can use any diff-tool to see the differences. Below snippets are example on changes in cycfg_gap.c and main.c.

SnipChangesInGAP.png

 

SnipChangesInMain.png

 

To check the full diffs, you may see directly on the files inside the attachment.
You can also modify the code to have longer name with more random digits.
WARNING: ANY MODIFICATION IN cycfg_gap.c WILL BE GONE (REPLACED) IF USING BT Configurator AGAIN.
I strongly suggest to save / backup any changes in that file!

If you still have any doubt(s), please feel free to ask.
Or if it is in another topic, you may also create new thread.

Best regards,
Muhammad Nanda

Hello @srini_a,

I am sorry, just want to follow up. 🙂
Have you try / check the code in my previous reply ?
Or, do you have any comments regarding that ?

Thank you and regards,
Muhammad Nanda

0 Likes

I am sorry @srini_a ,

Is my proposed solution fit to you ?
Or, do you have any comment(s) for this ?

Thank you and regards,
Muhammad Nanda

0 Likes

Hello @srini_a ,

If you do not have any further concern, I will mark my explanation as solution and lock this thread.
After locked, if you still have another issue, you may also create new thread. 🙂

Thank you and regards,
Muhammad Nanda

0 Likes