Programmatically Changing BLE device name

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

cross mob
Anonymous
Not applicable

I want to have the last 4 characters of my device name be the last 4 hex characters of the MAC address.

   

So in order to do this:

   

-How do I retrieve the device MAC address? 

   

-How do I programmatically set the device name ?

0 Likes
1 Solution
Anonymous
Not applicable

Use CyBle_GetDeviceAddress to get the device MAC address. Use CyBle_GapSetLocalName to set the device local name. Call this API before the advertisement start APIs so that the device advertises with the new address.

View solution in original post

0 Likes
3 Replies
Anonymous
Not applicable

Use CyBle_GetDeviceAddress to get the device MAC address. Use CyBle_GapSetLocalName to set the device local name. Call this API before the advertisement start APIs so that the device advertises with the new address.

0 Likes
Anonymous
Not applicable

Thanks.

   

 

   

I am testing on a few devices, and for every single device I am getting same address when calling CyBle_GetDeviceAddress  with the addr type set to 0 for public address.

   

 

   

I have 'Silicon generated "Company assigned" part of the address' checked in the BLE component, and the public address remains as:

   

00A050-XXXXXX

   

on every call to CyBle_GetDeviceAddress  I am getting: 0x80 0x95 0x19 0x29 0x49 0x80

   

Am I comparing two different addresses? Shouldn't the company prefix and 'die' assigned address be there?

0 Likes
Anonymous
Not applicable

Okay,

   

I got a little further following this advice: http://www.cypress.com/forum/proc-ble/update-device-name-id-during-advertising

   

I am now waiting until the BLESS state is event_close before getting the device address.

   

    while( CyBle_GetBleSsState() !=  CYBLE_BLESS_STATE_EVENT_CLOSE )
        {
            CyBle_ProcessEvents();
        }

   

(CyBle_GetDeviceAddress(&device_mac_addr)

   

This gets me unique mac addresses.

   

The other issue I ran into was that CyBle_GapSetLocalName was truncating the custom name I was setting based on the length I put in the component:

   

charLen = (uint8)CYBLE_GATT_DB_ATTR_GET_ATTR_GEN_MAX_LEN(CYBLE_GAP_DEVICE_NAME_INDEX + 1u);

   

Once I padded out the name I put in the component settings, this stopped truncating. 

   

Is there a better way to do that?

0 Likes