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

cross mob
musteresel
Level 2
Level 2
5 sign-ins First like received First solution authored

Hi,

I'm trying to change the local name of my device after starting the BLE stack, I've tried with both

  • CyBle_GapSetLocalName(new_name);
  • attributeValue.attrHandle = 3; // handle of local device name!
    attributeValue.value.val = (uint8_t * const) new_name;
    attributeValue.value.len = strlen(new_name);
    uint8_t flag = CYBLE_GATT_DB_LOCALLY_INITIATED;
    CyBle_GattsWriteAttributeValue(&attributeValue, 0, &cyBle_connHandle, flag);

Unfortunately, in both cases the device name (when read) still sends the old (larger) length. I've verified this using a BLE sniffer:

musteresel_0-1687780073744.png

Old name, set via PSoC Component dialoge: "xxxxxxxxxxxxxxxxxxxxxx"

New name, set via the above approaches: "St.Do 34567890_"

I've looked into the generated code for CyBle_GapSetLocalName() and found this:

musteresel_1-1687780340160.png

In other words, the generated code does not set the new actual length.

I'm using the BLE component v3.60:

musteresel_2-1687780463897.png

 

Chips used are

  • CYBLE-224110-00
  • CYBLE-224116-01

How do I write an attribute value (like the local device name) with a new (shorter) length?

 

 

0 Likes
1 Solution
musteresel
Level 2
Level 2
5 sign-ins First like received First solution authored

For reference, I've managed to adjust the length using:

 

CYBLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(3, strlen(new_name));

 

 

This is after writing via CyBle_GattsWriteAttributeValue as shown in the question.

View solution in original post

4 Replies
musteresel
Level 2
Level 2
5 sign-ins First like received First solution authored

For reference, I've managed to adjust the length using:

 

CYBLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(3, strlen(new_name));

 

 

This is after writing via CyBle_GattsWriteAttributeValue as shown in the question.

MuhammadNanda_K
Moderator
Moderator
Moderator
50 solutions authored 250 sign-ins 250 replies posted

Hello @musteresel ,

Glad to hear your issue is solved and thanks for joining our community. 🙂
But to make sure, is your final code look like this:

 

            attributeValue.attrHandle = 3; // handle of local device name!
            attributeValue.value.val = (uint8_t * const) new_name;
            attributeValue.value.len = strlen(new_name);
            
            CyBle_GattsWriteAttributeValue(&attributeValue, 0u, &eventParam, CYBLE_GATT_DB_LOCALLY_INITIATED);
            CYBLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(3, strlen(new_name));
            
            CyBle_GapSetLocalName(new_name);

 

?

And also do you insert this snippet under event CYBLE_EVT_STACK_ON or other place ?
This will be important in case other people in future wanted to do the same thing. 🙂

Thank you and regards,
Muhammad Nanda

0 Likes

Hi,

the final code looks similar to this:

 

attributeValue.attrHandle = 3; // handle of local device name!
attributeValue.value.val = (uint8_t * const) new_name;
attributeValue.value.len = strlen(new_name);
uint8_t flag = CYBLE_GATT_DB_LOCALLY_INITIATED;
CyBle_GattsWriteAttributeValue(&attributeValue, 0, &cyBle_connHandle, flag);
// Add error handling here! Do not write length if longer than max!!
CYBLE_GATT_DB_ATTR_SET_ATTR_GEN_LEN(3, strlen(new_name));

 

 

It can be placed where ever necessary. In my case I have it in a function, and call this function once under the event `CYBLE_EVT_STACK_ON` as well as when processing the current state (so outside of the central event handler function which is call by CyBle_ProcessEvents).

It's important however to NOT write a string value that is longer than the value (can be a placeholder) that is set in the component configuration dialog. The generated code only allocates (static) storage for the device name with the length of the string in the component dialoge.

So in my case, I have a placeholder that is as long as the name will be maximally, and then set shorter names via the mentioned method.

Best, Daniel

Hello Daniel @musteresel ,

Thanks for the good explanation! 🙂
Hopefully your project will be going well and you can always join the community forum if you have any issue or have proposed solution. 

I will close this thread then.
Any other inquiry, please do not hesitate to create new thread. 🙂

Best regards,
Muhammad Nanda

0 Likes