4 Replies Latest reply on Oct 20, 2016 4:31 PM by pado_1228851

    Writing the Device Name Characteristic? (almost there!)


      I am able to write a new device name to a peripheral from an iOS device and have it appear in the advertising data using this code:


      char newName[] = "any new name";




      Cyble_GapUpdateAdvData(cyBle_discoveryModeInfo.advData,  CyBle_discoveryModeInfo.scanRspData);


      And following Zadek's method at http://www.cypress.com/forum/psoc-4-ble/writing-device-name-characteristic?source=search&keywords=PSoC4%20BLE%20write%20to%202A00%20characteristic&cat=community, I have also made a GATT characteristic for the new device name which I can easily write to with an iOS device.  Here is that code:




           wrReqParam = (CYBLE_GATTS_WRITE_REQ_PARAM_T *)eventParam;


           if( wrReqParam->handleValPair.attrHandle == CYBLE_MY_SERVICE_DEVICE_NAME_CHAR_HANDLE ){


           CyBle_GattsWriteAttributeValue( &wrReqParam->handleValPair, 0, &connectionHandle,         CYBLE_GATT_DB_LOCALLY_INITIATED);


           CyBle_GattsWriteRsp( connectionHandle );




      Do I now use a Cyble_GattsRead AttributeValue() on my device name characteristic so that I may assign the read-response to my char newName[] variable?  If so, what does that code look like?  Thanks.




      Also, I would like to put the new name in the SFLASH as Zadek did, so that it survives power downs.  What does that code look like?  (the link provided no longer works) Thanks again.

        • 1. Re: Writing the Device Name Characteristic? (almost there!)

          You can update device name for advertisement as below. 


          cyBle_discoveryModeInfo.cyBle_discoveryData[5] = newName[0];


          cyBle_discoveryModeInfo.cyBle_discoveryData[5] = newName[1];




          and so on. 




          You also need to change cyBle_discoveryModeInfo.cyBle_discoveryData[3] to length of name. 

          • 2. Re: Writing the Device Name Characteristic? (almost there!)

            Thanks pvkv.  Working fine.  I can write a new name from my phone to the peripheral and have that new name appear in the advertising packet.  Now I want to flash that new name to the SFLASH so that the new name survives the peripheral's  power downs.  I have had a look at the User_SFLASH_Write-2 project and have added WriteUserSFLASH.c and .h to my project.  And I've calculated my useable SFLASH row numbers to be from 562 to 1023 (does that sound right?)  I've not yet been able to flash to memory.


            How should I use WriteUserFlashRow()?  Like this WriteUserFlashRow(563, &newName);?


            And how do I get newName[] back into the advData upon power up?



            • 3. Re: Writing the Device Name Characteristic? (almost there!)

              I can write to a characteristic and then have that characteristic update the peripheral's local name using the following code:




              Stack_Handler( uint32 eventCode, void *eventParam )




              CYBLE_GATTS_WRITE_REQ_PARAM_T *wrReqParam;


              switch ( eventCode )






              case CYBLE_EVT_GATTS_WRITE_REQ:


              wrReqParam = (


              CYBLE_GATTS_WRITE_REQ_PARAM_T *)eventParam;


              switch ( wrReqParam->handleValPair.attrHandle )






              sensorNameHandle.attrHandle =




              sensorNameHandle.value.val =




              sensorNameHandle.value.len = 19;


              CyBle_GattsWriteAttributeValue( &sensorNameHandle, 0, &connectionHandle,




              CyBle_GattsWriteAttributeValue( &wrReqParam->handleValPair, 0, &connectionHandle,






              uint8 name[19] = {""};


              sensorNameHandle.attrHandle =




              sensorNameHandle.value.val = name;


              sensorNameHandle.value.len = 19;






              int length = sizeof(name);


              int i;


              for(i=0; i<length; i++){


              cyBle_discoveryData.advData[i+5] = name[i];




              cyBle_discoveryData.advData[3] = length;




              const char *)name);








              But I can only successfully set 12 characters of the local name.  If I try to write more than 12 characters from my iOS device then the local name isn't reset.  Also if I send less than 12 characters, say I send 9 characters, then the final 3 characters from the previous local name still remain as part of the new local name.  I've worked with the iOS code and am pretty sure that the problem is in my peripheral's code.  Any ideas what is happening?  There is enough room in my advertising scan response packet for 20 characters, all of which show upon the first read by the iOS upon the peripheral's power up.  The 12 character problem only shows up after the first write from the iOS to the peripheral.

              • 4. Re: Writing the Device Name Characteristic? (almost there!)

                Please disregard the above problem.  I am headed in another directions.  thanks.

                1 of 1 people found this helpful