Cyble 212019 scan stops after a while in Central and peripheral mode

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

cross mob
DhDa_2432241
Level 5
Level 5
5 likes given First like received First like given

Hello all,

I have my BLE configured as follows:

1.PNG

2.PNG

My code is as follows

/******************************S T A R T ********* M A I N . C ******************************/

void monitorCybleState();

int main(){

   CyBle_Start(StackEventHandler);

   for(;;){

       monitorCybleState();

   }

   return 0;

}

void monitorCybleState()

{

    switch(CyBle_GetState()){

        case CYBLE_STATE_STOPPED:

            break;

        case CYBLE_STATE_INITIALIZING:

            break;

       

        case CYBLE_STATE_CONNECTED:

            break;

       

        case CYBLE_STATE_ADVERTISING:

            break;

       

        case CYBLE_STATE_SCANNING:

            break;

       

        case CYBLE_STATE_CONNECTING:

            break;

       

        case CYBLE_STATE_DISCONNECTED:

            CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);

            CyBle_GapcStartScan(CYBLE_SCANNING_FAST);

            break;

        default:

            break;

    }

}

/******************************E N D ********* M A I N . C ******************************/

/**********************S T A R T *********** E V E N T . C **********************/

void StackEventHandler(uint32 event, void* eventParam){

    switch(event){

           case CYBLE_EVT_STACK_ON:

                  break;

          case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:

                 printf(".");

                 break;

          case  CYBLE_EVT_GAPC_SCAN_START_STOP:

                  printf("CYBLE_EVT_GAPC_SCAN_START_STOP\r\n");

                  break;

           default:

                 break;

   }

}

/**********************E N D **************** E V E N T . C ***********************/

/**********************OBSERVATIONS******************/

I see that advertisement and scanning are started. I can see my BLE advertising with the payload I configured. Also,the scanning is active as I can see the dots on my console. After a while I don't see any dots which means there are no scan events. This implies that scanning has stopped because there are active BLE devices emitting beacons all the time. I printed the value of CyBle_GetState() and it shows 4.

4 corresponds to CYBLE_STATE_SCANNING.

This implies that Cyble is still in scanning state but it is not scanning anymore. I am not sure why. I added debug messages to see if somehow CyBle_GapcStopScan() is being called. I didn't see my debug messages on console. So no. I am not sure why scan is stopping after a while. It stops at random times. However, advertisement is functioning well.

As of now the only way to fix this is using stack restart which is CyBle_Stop() and Cyble_Start() which starts the advertisement and scan again. Any suggestions on how to fix this without stack restart?

Thanks

Dheeraj

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

Hello Dheeraj,

    Since, your device is configured as "Central and Peripheral" and you are starting 'Advertising' and 'Scanning' at the same time. If you have set the Advertising type as 'Connectable Undirected Advertising' ( See the attached BLE component Screen shot) then you will get an HCI error. Both 'Connectable Undirected Advertising' and 'Scanning'  is not possible at the same time because PSoC BLE /PRoC BLE device supports only one connection at a time.

What you could do is -

1) Either change the Advertising type as 'Scannable Undirected Advertising' or Non-connectable Advertising'  OR

2) Do the time multiplexing between Central ( Scanning ) role and Peripheral Role( Advertising) role of the device. You can refer the example project from here

          PSoC-4-BLE/100_Projects_in_100_Days/Day012_Central_Peripheral at master · cypresssemiconductorco/PSo...

Regards,

Gyan

  

View solution in original post

17 Replies