2 Replies Latest reply on Jul 8, 2020 1:38 PM by DeCo_1926091

    How does PSoC 4 BLE prevent > 4 bounded devices

    DeCo_1926091

      I know there is a limit of four bonded devices allowed with a PSoC 4 BLE and that this number is specified as a constant which cannot me changed, but exactly how does it prevent more than four devices from being bonded?  I'm interested in this because I need to prevent more than one device from being bonded to my peripheral.  I can read the bonded devices count and not allow bonding if the count >=1, but I haven't been able to find where to put that in any of the code examples I've seen, such as Ble_Bonding (Day 15 in the 100 projects...).  

       

      Thanks for your help,

      Dennis

        • 1. Re: How does PSoC 4 BLE prevent > 4 bounded devices
          PY_21

          Hello,

           

          Maximum devices bonded are specified by CYBLE_GAP_MAX_BONDED_DEVICE, internally BLE Stack will check this value. If you want to allow only one device to bond with the peripheral then before storing the bonding data check for the bonded devices count. If the count is 0 then store the bonding data(CyBle_StoreBondingData() API will stores the bonding data from RAM to the dedicated Flash) or if the count is greater than or equal to 1 then don't store that device bonding data(as shown in below code).
          *********************************************
          CYBLE_GAP_BONDED_DEV_ADDR_LIST_T bondedDeviceList;

          apiResult = CyBle_GapGetBondedDevicesList(&bondedDeviceList);

          if(bondedDeviceList.count==0)       
          {
                  if((cyBle_pendingFlashWrite != 0u))
                  {
                      // Store Bonding informtation to flash
                      apiResult = CyBle_StoreBondingData(0u);
                      if ( apiResult == CYBLE_ERROR_OK)
                      {
                          printf("Bonding data stored\r\n");
                      }
                      else
                      {
                          printf ("Bonding data storing pending\r\n");
                      }
                  }       
          }
                
          else(bondedDeviceList.count>=1)  
          {
             printf ("Bonded device list count reaches to 1 \r\n");       
          }

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

           

          Thanks,

          P Yugandhar.

          • 2. Re: How does PSoC 4 BLE prevent > 4 bounded devices
            DeCo_1926091

            PY,

            Two questions:

             

            1.  In the code you sent, what makes cyBle_pendingFlashWrite != 0?  It seems to me that it should be set as a result of calling CyBle_StoreBondingData.  If so, then  CyBle_StoreBondingData would never be called because the pending flash write would never be anything but zero.

             

            2.  I think that once the storing of bonding data has been initiated (however that happens) the bonding devices list count is incremented, before the process is completed.  If so, all the code in the if count = 0 will not be executed which means that the apiReturn can never be tested for when it becomes CYBLE_ERROR_OK, since it takes more time to complete the storing Process than once around the main while loop.

             

            Am i wrong about this?

             

            Thanks,

            Dennis

             

            Edit by Dennis on July 8, 2020:

            Apparently, the answer to the first question is that the stack sets the cyBle_pendingFlashWrite flag.  Then, based on this flag my code has to call the CyBle_StoreBondingData.  Unfortunate naming.  Perhaps if the flag had been called something else, such as "startBondingNow" or "readyToBond" it would have made more sense.