Run time switching between broadcaster and observer

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

cross mob
Anonymous
Not applicable

I am considering the following BLE modules for development. My use case is I want the module to sense/scan identify the presence of another broadcaster module with a specific name/identifier. In case it does not identify one, then this one (the one currently scanning) should start broadcasting. To meet this requirement, I want to know if I can swap between BROADCASTER and OBSERVER during runtime.

In short, Scan for broadcaster -> If no broadcaster with specific name identified -> Start broadcasting. This is the algorithm.

Please guide. Thanks in advance.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
GyanC_36
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

Here is the sample example project-

View solution in original post

8 Replies
Owen_Zhang123
Moderator
Moderator
Moderator
5 questions asked 500 solutions authored 250 sign-ins

You need to set a timeout for the scan. When the time out happens, switch to broadcast.

To get the scan result, please refer to (CYBLE_GAPC_ADV_REPORT_T *) eventParam; in the CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT event.

When switch to broadcast, use the API CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);

Anonymous
Not applicable

Thanks.

What profile / GAP role should I prefer to set for the nodes on the "Configure BLE" GUI of PSoC creator IDE?

Peripheral / Central / Broadcaster / Observer?

0 Likes

Please set the BLE component to Client and Sever(GATT Client and Sever).

Anonymous
Not applicable

Thanks. I will give a try.

0 Likes
lock attach
Attachments are accessible only for community members.
GyanC_36
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

Here is the sample example project-

Anonymous
Not applicable

Thanks a lot for sharing the project. I will give it a try.

0 Likes
Anonymous
Not applicable

Dear Gyan,

Referring to the snippet below, are you turning on the peripheral mode advertisement as soon as the stack is ON and then starting central mode discovery? I want all of my nodes to scan for any other advertising node. In case they dont find one, then the scanning node will start advertising. Can you please spare your valuable time and explain this snippet?

case CYBLE_EVT_STACK_ON:    /*BLE stack ON*/

                printf("Bluetooth ON:\r\n");

                cyBle_discoveryInfo.discProcedure=CYBLE_GAPC_OBSER_PROCEDURE;

                CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);

                CyBle_GapcStartDiscovery(&cyBle_discoveryInfo); 

break;

0 Likes

Hello rajvignesh_3582366 ,

     Based on your application, you can modify the logic as below.

-> On Stack On just start scanning.

case CYBLE_EVT_STACK_ON:    /*BLE stack ON*/

                printf("Bluetooth ON:\r\n");

                cyBle_discoveryInfo.discProcedure=CYBLE_GAPC_OBSER_PROCEDURE;            

                CyBle_GapcStartDiscovery(&cyBle_discoveryInfo);

In the event CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT , you are viewing all the nearby advertising nodes.

If you do not find a particular node , you can stop the scanning (CyBle_GapcStopDiscovery()) and start advertising (CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST)) .

In the shared code example, the device will do both observer scanning and advertising concurrently.

-Gyan

0 Likes