cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable


   

Dear cypress society,

   

 

   

Would you please prepare an application note that explains,

   

Hot to create our own custom profile and integrate our own ble write callbacks into soft,

   

 

   

Thanks in advance..

0 Likes
Reply
9 Replies
Anonymous
Not applicable

 Noted, we will shortly release an app note that details creation of your own custom BLE Profiles.

0 Likes
Reply
HeLi_263931
Honored Contributor II

I have seen while debugging that you should get a EVT_GATT_WRITE_REQ event in the BLE callback. There you get a structure as event parameter that has the name of the characteristic where the write goes to.

   

Don't forget to set set it as writable, and to send the write response afterwards.

   

Unfortunately I havent seen any event that corresponds to a read request 😞

0 Likes
Reply
Anonymous
Not applicable

Read requests are generally handled by BLE stack and thus, no such events are generated for application. The only thing application needs to take care of is to update the GATT database with new data, whenever such data is available. So when the Read request is sent from Client, BLE stack can send the response with updated data.  

   

General API for this purpose is CyBle_GattsWriteAttributeValue.

0 Likes
Reply
HeLi_263931
Honored Contributor II

OK, I succeeded in handling the GATT write request, and using the CyBle_GattsWriteAttributeValue call to make the attributes available for read. But I'm struggling in creating notifications for my custom characteristic. I'm following the code I'M seeing for the heart rate and battery level services.

   

So I'm calling regularly this code:

   
uint16 accel=0; void SimulateAcceleration() {     CYBLE_API_RESULT_T apiResult;     CYBLE_GATTS_HANDLE_VALUE_NTF_T ntfReqParam;      if (accelSimulation)     {         // simulate changes to the acceleration value         accel++;                 CYBLE_GATT_HANDLE_VALUE_PAIR_T        statusHandle;            statusHandle.attrHandle = CYBLE_ACCELHISTORY_DEHENDRIKLIPKACHARACTERISTICACCELCURRENT_CHAR_HANDLE;         statusHandle.value.val = (uint8*)&accel;         statusHandle.value.len = 2;         statusHandle.value.actualLen = 2;          CyBle_GattsWriteAttributeValue(&statusHandle,0,&connectionHandle,CYBLE_GATT_DB_LOCALLY_INITIATED);           if(accelNotification)         {             ntfReqParam.attrHandle = CYBLE_ACCELHISTORY_DEHENDRIKLIPKACHARACTERISTICACCELCURRENT_CHAR_HANDLE;             ntfReqParam.value.val = (uint8*)&accel;             ntfReqParam.value.len = 2;             ntfReqParam.value.actualLen = 2;                         apiResult = CyBle_GattsNotification(connectionHandle, &ntfReqParam);             // print result to the debug console             printf("%i\r\n", (int) apiResult);         }     } }
   

I see that the code is called, and the result of the notification call is 0, so it should be fine. I also see the value changing when I read it via the CySmart tool, but it receives no notifications (I'm using the CCCD for that, as I should).

   

Do I need to configure something else for the notification to work? (Its active in the settings of the characteristics).

   

I have attached the project too. Look in acs.c for the code, otherwise it follows the heart rate example, I copied heavily from there.

0 Likes
Reply
Anonymous
Not applicable

 Hi,

   

 

   

The client  characteristic of the "de.hendriklipka.characteristic.accel.current" has default items "notifications disabled" and indications idsabled" when you want notify the client abou this characterisitc the notifications has to be enabled.

   

 

   

Either client has to enable the notifications or you can enable it in your code by changing the client characteristic configurations item [0] to notifications enabled.

   

 

   

Regards,

   

Vikas.

0 Likes
Reply
HeLi_263931
Honored Contributor II

Maybe I should have mentioned that: I'm writing the enable value to it via CySmart. Thats where the 'if(accelNotification)' condition stems from. I listen to the write requests, and set that flag when I encounter write to the CCCD regarding the notification.

   

Do I need to set some other place in that event handler? I cannot see anything in the BAS / HRSS source codes that would do that.

0 Likes
Reply
HeLi_263931
Honored Contributor II

I just tested with the setting turned on by default (and setting my flag to 1 from the beginning) - nothing gets received by CySmart.

0 Likes
Reply
Anonymous
Not applicable

Try replacing "connectionHandle" with "cyBle_connHandle" when calling CyBle_GattsNotification in SimulateAcceleration function. 

0 Likes
Reply
HeLi_263931
Honored Contributor II

That did the trick! Many thanks. It might be useful to document that global variable somewhere

   

For anybody looking at my code and thinking that connectionHandle in server.c should be set correctly - no it wont. The event handling in debug.c (DebugOut()) gets the event first, and it never sends it to server.c (and neither does it set the connectionHandle then 😞

0 Likes
Reply