- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am trying to dynamically update the advertising packets sent by my PSoC 4 device in the "Central and Peripheral" project. I have seen the following thread:
Recommended method to update manufacturer data when NOT advertising
and have attempted to do this by changing the cyBle_discoveryModeInfo.advData->advData[] array before starting advertising. I have done this in the StackEventHandler's CYBLE_EVT_STACK_ON function:
/* Set adv data packet */
char deviceName[] = "12345678";
(cyBle_discoveryModeInfo.advData->advData)[3] = 0x09; //Set length
for(i=5; i<13; i++)
(cyBle_discoveryModeInfo.advData->advData) = deviceName[i-5];
cyBle_discoveryModeInfo.advData->advDataLen = 13;
CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
/* ------------------------- */
The issue I am having is that the advertising packet does not change, which I see by using the LightBlue app and looking at the device name. Interestingly, if I change the cyBle_discoveryModeInfo.r->respData array this way, it does change the response packet. However, I need to change the initial advertising packet as well. What am I doing wrong in this case?
Thank you very much.
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
From your attached code, you have just changed the device name and advdata length, the other data remains untouched, right?
One possible reason is regarding to mobile app you are using, which remains the old name even though it's changed. You can try to switch to another app, e.g. CySmart, to check whether this issue is still there.
If it is not effective, you can try to put the the code snippet from under swtich case to main loop with judging some boundary conditions, like -
- Whether BLE stack is on;
- Whether current state of advertisement is stopped;
- Whether the current BLE connection number is 0.
Of course, the most intuitive way is to enter debug mode and observe whether the adv data is changed or not before advertising start.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I should add that the declaration
char deviceName[] = "12345678";
is done before the switch(event) case structure, I just copy-pasted it into the CYBLE_EVT_STACK_ON case to avoid adding a large block of code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adding that declaration before the switch case structure solves your issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, I am just making the clarification because the code does not actually compile when the declaration is inside the case structure. The issue is separate from that and is still present.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
From your attached code, you have just changed the device name and advdata length, the other data remains untouched, right?
One possible reason is regarding to mobile app you are using, which remains the old name even though it's changed. You can try to switch to another app, e.g. CySmart, to check whether this issue is still there.
If it is not effective, you can try to put the the code snippet from under swtich case to main loop with judging some boundary conditions, like -
- Whether BLE stack is on;
- Whether current state of advertisement is stopped;
- Whether the current BLE connection number is 0.
Of course, the most intuitive way is to enter debug mode and observe whether the adv data is changed or not before advertising start.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi WangS_81,
I did what you suggested and checked the data using debug mode. It was what I expected. I then messed around with the BLE settings and had no luck. Eventually I tried to change the Local name display mode to Shortened and I can now see my changes to the local name when I connect to the device. For some reason the device name in the scan list (prior to connnection) is still the same name that one sets in the "Profiles" setting tab.
Since I was able to verify remotely that the data changes I am all set for now. Thank you!