BLE 4.1, 1 button input, random resolvable adress, and "FIFO" managment of bonded devices

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DeTo_1826166
Level 3
Level 3
First like received First like given

Hello,

I came here again and need some help after multiples workarounds..

The goal is to command a device ( a motorized door) with smartphones.

The smartphone have to be bonded with the door to allow easy use of the phone application.

There is only 1 button on the door, and the Ble module in use is in 4.1. Today's most device use resolvable random adress so can't use whitlistening to discard not allowed device to connect.

To work around the 1 button problem without the whitelist (i use just work and have to allow connection with 1 button), i do things like that :

/**********************************************************

        *                       GATT Events

        ***********************************************************/

        case CYBLE_EVT_GATT_CONNECT_IND:

/* This event is received when device is connected over GATT level */

            #ifdef PRINT_MESSAGE_LOG

UART_UartPutString("\n\r\tConnected_Ind \n\r");

               #endif

       

              connectionHandle = *(CYBLE_CONN_HANDLE_T  *)eventParam;

break;

case CYBLE_EVT_GAP_DEVICE_CONNECTED:

/* This event is received when device is connected over GAP layer */

/* This flag is used in application to check connection status */

deviceConnected = TRUE;

      

  CyBle_GapGetBondedDevicesList(&bondedDeviceList);         

      

           

            if (pairingAuth == TRUE) // button have been pressed (TRUE during 3 sec)

            {

                cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_NONE;

            }

            else if ((bondedDeviceList.count >= 1) && (connectionHandle.bdHandle == 4))

            {

           

                cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_NONE;

            }

            else if ((bondedDeviceList.count >= 2) && (connectionHandle.bdHandle == 3))

            {

           

                cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_NONE;

            }

             else if ((bondedDeviceList.count >= 3) && (connectionHandle.bdHandle == 2))

            {

           

                cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_NONE;

            }

              else if ((bondedDeviceList.count >= 4) && (connectionHandle.bdHandle == 1))

            {        

                cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_NONE;

            }

            else

            {

            cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_PAIRING_NOT_SUPPORTED;

            CyBle_GapDisconnect(connectionHandle.bdHandle);

            }

break;

        case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:

/* This event is received when device is disconnected */

  

              CyBle_GapGetBondedDevicesList(&bondedDeviceList);

       

                /* bonded device remove "FIFO handle" */

                if (bondedDeviceList.count == 4 )

                {

                    CyBle_GapRemoveOldestDeviceFromBondedList();

                //be sure to store it in flash

                if((cyBle_pendingFlashWrite != 0u) &&

                    ((UART_SpiUartGetTxBufferSize() + UART_GET_TX_FIFO_SR_VALID) == 0u))

                     {                           

                          if(CYBLE_ERROR_OK== CyBle_StoreBondingData(1u))                                     

                    }

           

                }

       

break;

It seems Ok to allow/discard the connection to a smartphone, with the input button  :

If non bonded, and if bonded just by checking the bdHandle and the Bonded device count.

But my problem is that i want to automaticaly delete the oldest bonded device when the the bonded list is full to allow this new device to be bonded.

The problem is that  it is not working, indeed     CyBle_GapRemoveOldestDeviceFromBondedList();  does not update the bd.handle.

I would like that the bdHandle == 3 is now 4, 2 now 3, 1 now 2

bondedDeviceList.count  is updated correctly so i just would like to "slide" the bdHandles number..

How can i go throught that, it seems not possible

We can't ask the users to delete all their smartphones if they want to add a new one.

Thanks for your help

0 Likes
1 Solution
Anonymous
Not applicable

I'm just using the remove oldest in my software, as that seems to work well. Admittedly, I'm only storing one bond at a time, and thus it might be the difference between 1 and more bonds stored.

There are example Cypress projects that demonstrate different software/hardware capabilities. You can check them out here:

PSoC-4-BLE/100_Projects_in_100_Days at master · cypresssemiconductorco/PSoC-4-BLE · GitHub

I don't know if there is an "example" for good bonding pratice, but there might be.

View solution in original post

0 Likes
6 Replies
Anonymous
Not applicable

apiresult = CyBle_GapGetBondedDevicesByRank(&bondList)

might be useful instead if the remove oldest is not working.

Another option is to store the order of oldest/newest yourself, and just remove the oldest one that you know when bonding a new one to overwrite it.

Epratt

0 Likes

Thanks for your answer.

Seems the right thing to do :

To remove a device :

CyBle_GapRemoveBondedDevice(&apiDeviceListRank4.bdAddr);

with apiDeviceListRank4 the oldest device rank.

And to retrieve the device (here for the most recent connected device) :

  else if ((bondedDeviceList.count >= 1) && (connectionHandle.bdHandle == apiDeviceListRank1.bdHandle))

      cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_NONE;

etc...

But it seems a little overcomplicated to do a common thing like that...

How currently is implemented similar behavior in bluetooth headphones for exemple ?

0 Likes
Anonymous
Not applicable

I'm just using the remove oldest in my software, as that seems to work well. Admittedly, I'm only storing one bond at a time, and thus it might be the difference between 1 and more bonds stored.

There are example Cypress projects that demonstrate different software/hardware capabilities. You can check them out here:

PSoC-4-BLE/100_Projects_in_100_Days at master · cypresssemiconductorco/PSoC-4-BLE · GitHub

I don't know if there is an "example" for good bonding pratice, but there might be.

0 Likes
DeTo_1826166
Level 3
Level 3
First like received First like given

Thanks for your answer and sorry for my late answer.

In all the exemples they just use Whitelistening, there is not exemple avalable for connection with recent Android Phone / IPhone despite it's a common thing.

0 Likes
Anonymous
Not applicable

True; Having a reconnection example would be nice. Something on my list of neverending things to do some day XD

0 Likes
DeTo_1826166
Level 3
Level 3
First like received First like given

Hello,

The project was in sleep from few months.

I have one last problem, with this method if i unbond from smartphone (delete the device in ios or Android Bluetooth menu), on the next connection with the psoc device, without using the pairing button, the smartphone bond again with the psoc device.

How can i solve this ?

0 Likes