9 Replies Latest reply on Jan 18, 2015 3:34 PM by user_78878863

    HOW TO REGISTER WRITE CALLBACKS OFF OUR OWN SERVICE

    yunus.ayhan


         

      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..

        • 1. Re: HOW TO REGISTER WRITE CALLBACKS OFF OUR OWN SERVICE
          gul

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

          • 2. Re: HOW TO REGISTER WRITE CALLBACKS OFF OUR OWN SERVICE
            user_78878863

            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 :(

            • 3. Re: HOW TO REGISTER WRITE CALLBACKS OFF OUR OWN SERVICE
              rohit.kumar

              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.

              • 4. Re: HOW TO REGISTER WRITE CALLBACKS OFF OUR OWN SERVICE
                user_78878863

                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.

                • 5. Re: HOW TO REGISTER WRITE CALLBACKS OFF OUR OWN SERVICE
                  vavc

                   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.

                  • 6. Re: HOW TO REGISTER WRITE CALLBACKS OFF OUR OWN SERVICE
                    user_78878863

                    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.

                    • 7. Re: HOW TO REGISTER WRITE CALLBACKS OFF OUR OWN SERVICE
                      user_78878863

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

                      • 8. Re: HOW TO REGISTER WRITE CALLBACKS OFF OUR OWN SERVICE
                        kris.p

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

                        • 9. Re: HOW TO REGISTER WRITE CALLBACKS OFF OUR OWN SERVICE
                          user_78878863

                          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 :(