BLE Connect to device in 2 different ways to distinguish between masters

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

cross mob
D_Sd_3235936
Level 4
Level 4
25 sign-ins 50 questions asked 25 replies posted

My device is the slave, that is being connected (not always in the same order) by 2 masters.

I would like to create two different connection ways/points to distinguish between the masters.

MASTER1 will always connect through "way1." MASTER 2 will always connect through "way2."

And I could map the connection handles according to the way they connected.

I was thinking about changing the MAC address/Name I am advertising periodically, by that creating 2 connection points.

First master will always connect through MAC-1/NAME-1.

Second master will always connect via MAC-2/NAME-2.

 

My question is how do I know through which mac they connect?

I can't rely on reading the advertise data upon connection as it may change.

0 Likes
1 Solution

Hello,

Connection event won't have that data.

To identify which master device is connected, you can do below process.
Before advertising, you can set the local name using Cy_BLE_SetLocalName() api and start advertising. After connection, you can read the local name using Cy_BLE_GetLocalName(). Using the local names, you can identify the master devices.

You can also identify the master devices by reading the peer bluetooth device address after connection using Cy_BLE_GAP_GetPeerBdAddr() api.

Thanks,
P Yugandhar.

View solution in original post

0 Likes
5 Replies
lock attach
Attachments are accessible only for community members.
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Hello,

In BLE Component--> in GAP Settings, you can use multiple Peripheral configurations as shown in attached image. When starting the advertisement, you can set the index of the peripheral configuration as shown below.

*****************************************************************************************
apiResult = Cy_BLE_GAPP_StartAdvertisement(CY_BLE_ADVERTISING_FAST, CY_BLE_PERIPHERAL_CONFIGURATION_0_INDEX);

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

For the first master, you can use one peripheral configuration structure. Similarly, for the second master, you can use another peripheral configuration structure.
Please let me know if this helps for your application.

Thanks,
P Yugandhar.

0 Likes
D_Sd_3235936
Level 4
Level 4
25 sign-ins 50 questions asked 25 replies posted

Thanks,

Another question regarding the solution, 

Upon getting a connection event,

How will I know to which peripheral advertisement the connection was made?

Does the connection event hold that data?

0 Likes

Hello,

Connection event won't have that data.

To identify which master device is connected, you can do below process.
Before advertising, you can set the local name using Cy_BLE_SetLocalName() api and start advertising. After connection, you can read the local name using Cy_BLE_GetLocalName(). Using the local names, you can identify the master devices.

You can also identify the master devices by reading the peer bluetooth device address after connection using Cy_BLE_GAP_GetPeerBdAddr() api.

Thanks,
P Yugandhar.

0 Likes
D_Sd_3235936
Level 4
Level 4
25 sign-ins 50 questions asked 25 replies posted

My concern is because I am constantly switching between 2 names/macs.

Please see this flow:

 

Advertising  Name1/Mac1

Advertising Name2/Mac2

Connection event received. ( for Name2/Mac2)

---------  > (here!) Advertisement changed to Name1/Mac1

Cy_BLE_GetLocalName() : I read Name1/Mac1 when actually connection was made during Name2/Mac2.


Can this happen?

Is there a solution to this case?

 

Thanks

0 Likes
lock attach
Attachments are accessible only for community members.

Hello, 

You have to the set the local name using Cy_BLE_SetLocalName() api, then only in the advertisement packet(if local name is enabled as shown in attached image) you can able to see the Local name advertising with Name2.

Thanks,

P Yugandhar.

0 Likes