Whitelist implementation in custom central and storing the address even after Reset

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

cross mob
Anonymous
Not applicable

Hello,

I have my custom client central project which connect and with peripheral and then disconnects. Meanwhile it read the characteristics values from peripheral and displays on UART terminal. In this project I can connect with any number of peripheral sequential and read the characteristics and then disconnect. And it takes about 80 ms in total for one peripheral connect+Data Read+Disconnect and then go to scanning mode and then so on......

I want to have now that my central can have upto 8 devices in whitelist (or store the device address) and then during sequential read,  remove the scanning part after disconnect and connect directly to the device whose address has been stored in central.

As I understood the only approach is to have with whitelist implementation.

Is there any other way to do this? If yes then can someone explain me how to go about?

I looked at the example project but could not able to implement properly. Past week I tried but no success. Can anyone help to correct or point out me to write direction.

I am attaching my central client project.

Thank you

0 Likes
1 Solution
Anonymous
Not applicable

Looking at your code, you are already comparing the addresses of your saved addresses with the scan results for the devices you already have.

If you want the device addresses stored in flash, then you will need to save the device addresses to the flash using a flash write sequence (which I don't see in your project btw).

(peedDeviceInfo[] is currently being stored in RAM).

Your approach and code all looks good. I would recommend debugging or checking the values for:

  • WptsScanProcessEventHandler(advReport)
  • newDevice
  • advDevices < CYBLE_MAX_ADV_DEVICES

I would also change this:

for(newDevice = 1u, i = 0u; i < advDevices; i++)

                    {

                        /* Compare device address with already logged one */

                        if((memcmp(peedDeviceInfo.peerAddr.bdAddr, advReport->peerBdAddr, CYBLE_GAP_BD_ADDR_SIZE) == 0))

                        {

                            DBG_PRINTF("%x: ",i);

                            newDevice = 0u;

                            break;

                        }

                    }

to this (for clarity of code):

newDevice = 1u;

for(i = 0u; i < advDevices; i++)

                    {

                        /* Compare device address with already logged one */

                        if((memcmp(peedDeviceInfo.peerAddr.bdAddr, advReport->peerBdAddr, CYBLE_GAP_BD_ADDR_SIZE) == 0))

                        {

                            DBG_PRINTF("%x: ",i);

                            newDevice = 0u;

                            break;

                        }

                    }

Otherwise, the code looks good. Are there specific things that are breaking/not working? Giving some points on what exactly is breaking would help

View solution in original post

5 Replies
Anonymous
Not applicable

Looking at your code, you are already comparing the addresses of your saved addresses with the scan results for the devices you already have.

If you want the device addresses stored in flash, then you will need to save the device addresses to the flash using a flash write sequence (which I don't see in your project btw).

(peedDeviceInfo[] is currently being stored in RAM).

Your approach and code all looks good. I would recommend debugging or checking the values for:

  • WptsScanProcessEventHandler(advReport)
  • newDevice
  • advDevices < CYBLE_MAX_ADV_DEVICES

I would also change this:

for(newDevice = 1u, i = 0u; i < advDevices; i++)

                    {

                        /* Compare device address with already logged one */

                        if((memcmp(peedDeviceInfo.peerAddr.bdAddr, advReport->peerBdAddr, CYBLE_GAP_BD_ADDR_SIZE) == 0))

                        {

                            DBG_PRINTF("%x: ",i);

                            newDevice = 0u;

                            break;

                        }

                    }

to this (for clarity of code):

newDevice = 1u;

for(i = 0u; i < advDevices; i++)

                    {

                        /* Compare device address with already logged one */

                        if((memcmp(peedDeviceInfo.peerAddr.bdAddr, advReport->peerBdAddr, CYBLE_GAP_BD_ADDR_SIZE) == 0))

                        {

                            DBG_PRINTF("%x: ",i);

                            newDevice = 0u;

                            break;

                        }

                    }

Otherwise, the code looks good. Are there specific things that are breaking/not working? Giving some points on what exactly is breaking would help

Anonymous
Not applicable

Hey Pratt,

Thanks man for replying.

I will try to do debugging this weekend and see how it goes.

Ya I want to store address in flash so that I can use it later. Do you happened to know any example or so for reference?

PS: The writing and reading from characteristics works now good. Thanks for guidance

0 Likes
Anonymous
Not applicable

You're welcome.

There are several examples for flash writing/reading, but it makes things a lot more complicated. I would recommend getting your project working with just the BLE portion first, so that it is a step-at-a-time

But, for the flash writing, you need to have the cpu clock running at a certain higher frequency, which means that you will not be able to do low power while saving the flash, and it could potentially interfere with timing for the BLE wireless operation if it requires a change in the clock frequency in order to write.

Here are some examples for you: Alan Hawse has good experience, and his tutorial should be helpful: PSoC 4 Flash Write - IoT Expert

Here is a good one on the cypress forums: Re: read/write flash

Another similar thread (this one is not as useful possibly): Re: To store data in flash

Some useful info on flash protection here: Self Writing Flash with Security in Kill Mode

PS: I'm glad the characteristics are working well now

0 Likes
Anonymous
Not applicable

That's very helpful Pratt

But I am a bit confused now regarding using function CyBle_GapAddDeviceToWhiteList() . So that means I don't have to put the address in whitelist but directly store in SFLASH and use it as needed (And this will remove the scanning part after disconnecting from sensor as I can access the address and connect without scanning?)

If this is true then what is the use of CyBle_GapAddDeviceToWhiteList() ??

or

I have to ADD the device into white list for my scanning problem?

0 Likes
Anonymous
Not applicable

Just different ways to handle it; You can either store the information to flash directly yourself, or use the cypress whitelist to handle the addresses. (I don't know if it is stored in RAM or not, as I used the BondedDevices list instead myself)

Using the CyBle_GapAddDeviceToWhiteList() should be doing what you want for having 8 devices in a whitelist of peripherals to get the data from. (But it won't support higher numbers than 8 devices in the whitelist) I think, that if you have the address stored in the whitelist, then you should be able to get the whitelist addresses with CyBle_GapGetDevicesFromWhiteList(), and use the bdAddresses from that to directly connect with the device (obviously, trying to connect to a not-present device will fail/timeout).

The whitelist addresses are stored in RAM however (see here: http://origin-www.cypress.com/forum/psoc-4-ble/whitelist-just-ram), so it will not be stored between resets/power offs. Thus, you will need to get the whitelist addresses and store them into flash using the CyBle_StoreAppData() function for all of the whitelist addresses you want to keep over power cycles.

The whitelist is a method of filtering devices detected when scanning (same as a whitelist for networking), but it is applied to scanning and incoming connection requests if you have it configured that way. Thus, if you have the BLE component configured to use whitelist when scanning, then it will only return the scan results pertaining to devices already in your whitelist. (Under the BLE component, scanning settings, you can set whitelist only, or all; same for connection/advertising too I believe)

I believe your scanning problem was an issue with not seeing the devices as you were scanning due to the whitelist-only setting being enabled, and not having any device addresses in the whitelist. Either removing the whitelist filter on the scanning, or adding your device addresses to the whitelist will fix that issue

0 Likes