3 Replies Latest reply on Nov 25, 2020 10:16 PM by SudheeshK_26

    How can I change custum service "data" from the code?

    BeKA_4795986

      Hi,

       

      I am trying to broadcast counter value. You can see BLE configuration below:

       

       

      resim_2020-11-13_011644.png

       

      In the picture, as you can see there is "Data" bar. I tried to change its value from the code using  "cy_ble_discoveryModeInfo->advData->advData[28] = newData" and "Cy_BLE_GAPP_UpdateAdvScanData(cy_ble_discoveryModeInfo)".

       

      How can I do this and where should I write related code pieces in my main file?

       

      Thanks a lot!

        • 1. Re: How can I change custum service "data" from the code?
          PY_21

          Hello BeKA_4795986 ,

           

          After advertisement start, you can use Cy_BLE_GAPP_UpdateAdvScanData API functoin for setting the advertisement and scan response data while advertising is ongoing. On completion of this operation, the GAP Peripheral application receives the CY_BLE_EVT_GAPP_UPDATE_ADV_SCAN_DATA_COMPLETE event. This API function must be called when Cy_BLE_StackGetBleSsState() returns the CY_BLE_BLESS_STATE_EVENT_CLOSE state. See the following sample code segment:

          ************************************************************************

               if(Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_ADVERTISING)
               {
                  if(Cy_BLE_StackGetBleSsState() == CY_BLE_BLESS_STATE_EVENT_CLOSE)
                  {
                     /* Updating the ADV and SCAN Response data */
                     cy_ble_discoveryModeInfo->advData->advData[5]='A';
                     cy_ble_discoveryModeInfo->scanRspData->scanRspData[5]='S';
                     /* Updating the ADV and SCAN Response data */
                     Cy_BLE_GAPP_UpdateAdvScanData(cy_ble_discoveryModeInfo);
                  }
               }

          ************************************************************************

           

          Thanks,
          P Yugandhar.

          1 of 1 people found this helpful
          • 2. Re: How can I change custum service "data" from the code?
            BeKA_4795986

            Hello Yugandhar,

             

            I am very appreciate to your answer. I would like to share my code with you. Still, I am doing something wrong...

             

            void StackEventHandler(uint32_t event, void *eventParam)

            {

                switch(event) {

                    case CY_BLE_EVT_STACK_ON:

                    case CY_BLE_EVT_GAP_DEVICE_DISCONNECTED:

                        Cy_BLE_GAPP_StartAdvertisement(CY_BLE_ADVERTISING_FAST, CY_BLE_BROADCASTER_CONFIGURATION_0_INDEX);

                        Cy_BLE_GAPP_UpdateAdvScanData(cy_ble_discoveryModeInfo); //?

                        Cy_GPIO_Write(Pin_1_PORT,Pin_1_NUM,1);

                    break;

                   

                    case CY_BLE_EVT_GAPP_UPDATE_ADV_SCAN_DATA_COMPLETE:

                        if(Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_ADVERTISING)

                        {

                            if(Cy_BLE_StackGetBleSsState() == CY_BLE_BLESS_STATE_EVENT_CLOSE)

                            {

                                /* Updating the ADV and SCAN Response data */

                                cy_ble_discoveryModeInfo->advData->advDataLen = 1;

                                cy_ble_discoveryModeInfo->advData->advData[28]=count++;

                                //cy_ble_discoveryModeInfo->scanRspData->scanRspData[5]='S';

                                /* Updating the ADV and SCAN Response data */

                                Cy_BLE_GAPP_UpdateAdvScanData(cy_ble_discoveryModeInfo);

                            }

                        }

                    break;

                   

                    case CY_BLE_EVT_TIMEOUT:

                        Cy_GPIO_Write(Pin_1_PORT,Pin_1_NUM,0);

                    break;

                   

                    default:

                    break;

                }

            }

             

             

            int main(void)

            {

                cy_en_ble_api_result_t apiResult;

             

             

                __enable_irq();

               

                apiResult = Cy_BLE_Start(StackEventHandler);

               

                CY_ASSERT(apiResult == CY_BLE_SUCCESS);

                for(;;)

                {

                    /* Place your application code here. */

                    Cy_BLE_ProcessEvents();

                }

               

            }

            • 3. Re: How can I change custum service "data" from the code?
              SudheeshK_26

              Hello,

               

              As you can see from our documentation (Cypress PSoC 6 Bluetooth Low Energy Middleware Library 3.50: More Information (cypresssemiconductorco.github.io)), the event CY_BLE_EVT_GAPP_UPDATE_ADV_SCAN_DATA_COMPLETE is generated after calling the API Cy_BLE_GAPP_UpdateAdvScanData(). But, as per your code, you will call this API only after you receive CY_BLE_EVT_GAPP_UPDATE_ADV_SCAN_DATA_COMPLETE event.

               

              Could you please modify your main() function as below and see if it resolves your issue? (Also, remove the call to Cy_BLE_GAPP_UpdateAdvScanData() from the event CY_BLE_EVT_GAPP_UPDATE_ADV_SCAN_DATA_COMPLETE ).

              int main(void)
              {
                  cy_en_ble_api_result_t apiResult;
                  __enable_irq();
                  apiResult = Cy_BLE_Start(StackEventHandler);
                  CY_ASSERT(apiResult == CY_BLE_SUCCESS);
                  for(;;)
                  {
                      /* Place your application code here. */
                      Cy_BLE_ProcessEvents();
                      
                      if(Cy_BLE_GetAdvertisementState() == CY_BLE_ADV_STATE_ADVERTISING)
                      {
                          if(Cy_BLE_StackGetBleSsState() == CY_BLE_BLESS_STATE_EVENT_CLOSE)
                          {
                              /* Updating the ADV and SCAN Response data */
                              cy_ble_discoveryModeInfo->advData->advData[5]='A';
                              cy_ble_discoveryModeInfo->scanRspData->scanRspData[5]='S';
                              /* Updating the ADV and SCAN Response data */
                              Cy_BLE_GAPP_UpdateAdvScanData(cy_ble_discoveryModeInfo);
                          }
                      }
                  }
              }
              

               

              Thanks and Regards,

              Sudheesh