Writing the device name characteristic

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

cross mob
JuVo_286221
Level 2
Level 2

I am trying to write the device name (0x2A00) of the GAP service (0x1800) from an iPhone or Android phone. We'd like to be able to set user-defined names for our devices (like Julian's Product) so that devices can be distinguished already when scanning for them. 

   
    What's the best way to do this?   
   

Should I set the name by ticking the 'write' checkmark on the device name characteristic and write the name directly over Bluetooth?

   

I tried to write it through iOS, but the GAP service doesn't show up like the other services. I don't know what lever to pull to make this work. 

   

Should I have a custom profile for sending the device name, and then setting the device name programmatically with the received string?

   

I read here that I might be able to use CyBle_ChangeAdLocalName for this purpose. I couldn't find any documentation on this though. 

0 Likes
1 Solution
JuVo_286221
Level 2
Level 2

We solved it now by using our custom service that we had already implemented. After getting the name from the phone, we call             CyBle_GapSetLocalName(device_name);

   

Then we store the device_name in flash.

View solution in original post

0 Likes
10 Replies
Anonymous
Not applicable

Enabling 'write' on the Device name characteristic is the best way to go, followed by sending the updated string over that characteristic after BLE connection.

   

But then there are two parts to this implementation:

   

1) When you receive the string over a Write request, use the CyBle_GattsWriteAttributeValue API to update the local database (DB). This will ensure that the next 'Read' on the same characteristic reflects the new value. Note that this change is reflected in the GATT DB only and can be seen only after BLE connection.

   

2) For truly achieving your goal of setting the new name as part of advertising, you need to update the Advertisement packet too. So once you have received the Write request over the Device Name Characteristic, along with Local GATT DB update, also update the device name part of cyBle_discoveryModeInfo.advData before you restart advertisement. Ensure that you do not exceed the limit of 29 bytes for payload in ADV packet.

0 Likes
Anonymous
Not applicable

Hi, I've got an almost similar case here but in my situation I used the CyBle_GapSetLocalName() API to change the device name because I wanted to set the name first before deployment. It did the job but how do i make it persistent? If I reset the device it will turn back to its original device name. Please advise.

   

Thanks!

0 Likes
Anonymous
Not applicable

Store the Device name set from Phone to SFLASH. The contents of the SFLASH remains even after powering off. Then at every power-up/reset, read the content of the SFLASH and use to set the name in ADV packet.

   

You can refer to the following project to implement SFLASH read and write:

   

https://github.com/cypresssemiconductorco/PSoC-4-BLE/tree/master/100_Projects_in_100_Days/Day029_BLE... 

0 Likes

roit,

   

I am getting a 404 error for your link.  Do you have another link to this project?

   

I am confused what you are advising--Do I create a new GATT Service with a characteristic for *Local Name* then handle the write request from the iOS device with the CYBLE_EVT_GATTS_WRITE_REQ in the stackhandler, using the CyBle_GapSetLocalName() and the value of the Local Name characteristic?

   

Thanks in advance

0 Likes
JuVo_286221
Level 2
Level 2

We solved it now by using our custom service that we had already implemented. After getting the name from the phone, we call             CyBle_GapSetLocalName(device_name);

   

Then we store the device_name in flash.

0 Likes
Anonymous
Not applicable

how do you read the name back from the write request?

0 Likes

Hi Nabeel, 

   

sorry for the belated response. Here's some sample code that expects a packet that starts with the BLE_DEVICE_NAME_IDENTIFIER followed by the device name as ASCII chars (can't handle other characters). Maybe that points you into the right direction.

   
uint8_t parse_device_name(char *data, int length) {          if (*(data + 0) != (char) BLE_DEVICE_NAME_IDENTIFIER) {         return 1; // first byte is not the identifier for this handler, continue with next hook in parser chain     } else {         // handle the packet         *(data + length)='\0';                  char *device_name_string = (data + 1);                  memset(device_name, 0, DEVICE_NAME_LENGTH);         sprintf(device_name, "%s",device_name_string);          // now you can update the name with CyBle_GapSetLocalName(device_name) and save the device name in flash          return 0;     } }
0 Likes
Anonymous
Not applicable

I just stumbled back to this post -- thanks for the response!

0 Likes
Anonymous
Not applicable

FYI: Section 3.12 here says that the GAP Service is filtered out on iOS: https://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf . Also interesting is that section 3.11.1 tells that the Device Name Characteristic should be writable.

0 Likes
Anonymous
Not applicable

Is there a way to handle a write request to the Characteristic with a UUID of 0x2A00? Or do we have to make a custom Service and Characteristic to go get around this limitation? 

   

If that's the case, then why does the BLE component allow you to check the 'write' box when configuring the profile? How else would BLE devices allow for updating the device name without a custom app?

0 Likes