11 Replies Latest reply on Dec 27, 2019 7:01 AM by PY_21

    CYBLE-2241100 device RSSI

    umg_4380326

      Hi,

       

      I have 3 cypress devices .I am successfully able to scan and advertise.

      Device A advertising, B that scans and sends the rssi of A to C

       

      I am using the structure  CYBLE_GAPP_DISC_DATA_T,

       

      BLE device is both central and peripheral, and in the stack on event I'm starting the advertisement and scanning at the same time.

       

      cyBle_discoveryData.advData[0]=buffer[0]; ,before advertising

      and then storing the RSSI in the buffer in the event CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT: buffer[0]=scanreport.rssi;

       

      But when i am scanning for device B i am getting the device B rssi and not the rssi of its scan response of device A .How can i achieve this?

      Can i get a sample code?

       

      Assistance is appreciated.

      Thanks,

      Shil

        • 1. Re: CYBLE-2241100 device RSSI
          PY_21

          Hello,

           

          When you are scanning for the Device B then at the central device(Device C), in the scan progress result event(CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT) you can get the rssi value of Device A in advertisement data of Advertisement report structure CYBLE_GAPC_ADV_REPORT_T. RSSI of Advertisement report structure will contains the Device B rssi value.

           

          At the central device(Device C):

           

          case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:

           

                  Advreport= *(CYBLE_GAPC_ADV_REPORT_T*) eventParam;

                

                  /*Check for Device B*/

                  if(Advreport.peerBdAddr[1]==0x01  && Advreport.peerBdAddr[2]==0x06  && Advreport.peerBdAddr[3]==0x0F  &&

                  Advreport.peerBdAddr[4]==0x09 && Advreport.peerBdAddr[5]==0x0A)

                  {

                     val=Advreport.rssi;         //Advreport.rssi will have the device B rssi value

                     val2[0]=Advreport.data[0];  //Advreport.data will contains the device A rssi value

                     }

          break;

           

           

          Thanks,

          P Yugandhar.

          • 2. Re: CYBLE-2241100 device RSSI
            umg_4380326

            Hey,

             

            i guess i need to do conversion?But i cant seem to guess.

            • 3. Re: CYBLE-2241100 device RSSI
              PY_21

              Hello,

               

              The RSSI value is a negative dBm value with a range limit of -85 <= N <= 0. So the RSSI value of device A (which you received through advertisement data at Device C) has to be converted to signed value.

              At Device B, store the RSSI value of device A in four buffers as shown in below and send these buffer data through advertisement data. At Device C, convert these values into a signed value.

               

              /* RSSI value is a signed value with 4bytes of hex value. so storing the RSSI value in 4 buffers */

                          buffer[0]=scanreport.rssi;                       

                          buffer[1]=(scanreport.rssi)>>8;

                          buffer[2]=(scanreport.rssi)>>16;

                          buffer[3]=(scanreport.rssi)>>24;

               

              For example, if the RSSI value of Device A is -12dBm then its hex value is 0XFFFFFFF4. Store these hex data in a buffer and send through advertisement.

               

              Thanks,

              P Yugandhar.

              • 4. Re: CYBLE-2241100 device RSSI
                umg_4380326

                Hey,

                 

                At device C, val[0]= scanreport->data[0]; this is where the value of the device A is right?

                so in this how can i convert the value at data[0] at device C to signed value?

                thanks

                • 5. Re: CYBLE-2241100 device RSSI
                  umg_4380326

                  Hey,

                   

                  I found that when in displaying the val[0]= scanreport->data[0];

                  the value obtained, if i do ( x-256) , i am getting the RSSI of the device A

                  i get device B rssi through scanreport->rssi as -15

                  also when i manually subtract the value (204-256 = -15)

                  (241-256 = -52 ) which is the rssi of the device A when i print the value in at device B

                   

                  but when i am implimenting in the code val[0]=( scanreport->data[0]) - 256; i am not able to get the result , the result is as same as above (but when i am calculating manually i am able to get the device A value ).How do i implement this in code?

                   

                  Thanks

                  1 of 1 people found this helpful
                  • 6. Re: CYBLE-2241100 device RSSI
                    umg_4380326

                    Hi,

                     

                    /** Pointer to advertising or scan response data */

                        uint8*     data;

                     

                    val[0]= scanreport->data[0];

                    this data has the value of both devices how can i neglect the device B value since i can get it directly from scanreport->rssi and get the other device value only?

                     

                    thanks

                     

                    • 7. Re: CYBLE-2241100 device RSSI
                      PY_21

                      Hello,

                       

                      When the device B is in central mode you stored the advertisement data(RSSI Value) of device A in some buffer in device B. After switching the device B to peripheral mode, you had updated the data buffer to structure CYBLE_GAPP_DISC_DATA_T before advertising as shown in below code. So, at the device C, scanreport->data[0] value will contains the device A rssi value only.

                             /* cyBle_discoveryData.advData[0]=buffer[0]; */

                       

                      Thanks,

                      P Yugandhar.

                      1 of 1 people found this helpful
                      • 8. Re: CYBLE-2241100 device RSSI
                        umg_4380326

                        Hey

                         

                        So the value i am obtaining is there an issue ?

                        Also i have another doubt at device C , if i need to detect another device B2, can  i check for the value using the val[1]= scanreport->data[1];? Or is there another approach?

                         

                        Thanks

                        • 9. Re: CYBLE-2241100 device RSSI
                          umg_4380326

                          Hi,

                           

                          At device central periphreal , this is what i am following

                          case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:

                           

                                  Advreport= *(CYBLE_GAPC_ADV_REPORT_T*) eventParam;

                              

                                  //Checking for Device B

                                  if(Advreport.peerBdAddr[1]==0xD0 && Advreport.peerBdAddr[2]==0x37  && Advreport.peerBdAddr[3]==0x84  &&

                                  Advreport.peerBdAddr[4]==0x00 && Advreport.peerBdAddr[5]==0x0A)

                                  {

                                      printf(" \r\n device detected \r\n ");

                                    

                                      CyBle_GapcStopScan();

                                      CyBle_ProcessEvents();

                                       printf("\r\n Device rssi value is %d",scanreport.rssi);

                           

                                      buffer[0]=scanreport.rssi;                        

                                      buffer[1]=(scanreport.rssi)>>8;

                                      buffer[2]=(scanreport.rssi)>>6;

                                      buffer[3]=(scanreport.rssi)>>24;

                                   

                                       cyBle_discoveryData.advData[0]=buffer[0]; 

                                       cyBle_discoveryData.advData[1]=buffer[1];

                                       cyBle_discoveryData.advData[2]=buffer[2];

                                       cyBle_discoveryData.advData[3]=buffer[3];

                           

                                       CyBle_GapUpdateAdvData(&cyBle_discoveryData,&cyBle_scanRspData);

                                     }

                          break;

                           

                          At device Central, this is what i am following

                          case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:

                           

                                  Advreport= *(CYBLE_GAPC_ADV_REPORT_T*) eventParam;

                              

                                  //Checking for

                                  if(Advreport.peerBdAddr[1]==0xD0 && Advreport.peerBdAddr[2]==0x36  && Advreport.peerBdAddr[3]==0x28  &&

                                  Advreport.peerBdAddr[4]==0x00 && Advreport.peerBdAddr[5]==0x0A)

                                  {

                                         RSSI=Advreport.rssi;         // device B rssi value

                                        printf("\r\n RSSI value of device central-peripheral is %d                \r\n",RSSI);

                                         val[0]=Advreport.data[0];  //Advreport.data will contains the device A                                                        rssi value

                             

                                          y = ((int)val[0]) - 255;

                                          printf("\r\n RSSI value of device B %d \r\n",y);

                           

                                     }

                          break;

                           

                          for val[0]=Advreport.data[0]; i am obtaining both the rssi values of device A (central -peripheral device)and device B (peripheral device)

                          • 10. Re: CYBLE-2241100 device RSSI
                            PY_21

                            Hello umg_4380326 ,

                             

                            At device B when the device is in central mode, you are storing the RSSI value(i.e., the distance between the Device A and Device B) of device A in a buffer and after switching it to peripheral mode, you are sending it through the advertisement data. So, at device C, advertisement report data of Device B (i.e., Advreport.data[0]) will contains the RSSI value of device A and device B. RSSI value of advertisement report(Advreport.rssi of Device B) will give the value of device B and device C. In order to check for different advertising devices RSSI value at device C, in the scan progress event(CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT) you need to check the address of different advertising devices in an advertisement report first and then you can get the RSSI values as shown in below code.

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

                            case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:

                             

                                    Advreport= *(CYBLE_GAPC_ADV_REPORT_T*) eventParam;

                                

                                    //Checking for peripheral device 1 with address

                                    if(Advreport.peerBdAddr[1]==0x44 && Advreport.peerBdAddr[2]==0x67  && Advreport.peerBdAddr[3]==0x89  &&

                                    Advreport.peerBdAddr[4]==0x01 && Advreport.peerBdAddr[5]==0x0A)

                                    {

                                           RSSI=Advreport.rssi;         // peripheral device 1 rssi value

                                       }

                                   //Checking for peripheral device 2

                            else if(Advreport.peerBdAddr[1]==0x56 && Advreport.peerBdAddr[2]==0x78  && Advreport.peerBdAddr[3]==0x90  &&

                                    Advreport.peerBdAddr[4]==0x05 && Advreport.peerBdAddr[5]==0x0A)

                                    {

                                           RSSI=Advreport.rssi;         // peripheral device 2 rssi value

                                       }

                             

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

                            Please refer to the Observer project in the GitHub, in this code example, central device scans for the nearby advertising devices continuously and shows the advertising report and scan response data of the advertising devices on the UART terminal (like Tera Term, Hyperterminal).

                            Please let me know if you have any questions.

                             

                            Thanks,

                            P Yugandhar.

                            • 11. Re: CYBLE-2241100 device RSSI
                              PY_21

                              Hello,

                               

                              Could you please add the below code in your Central project.

                              At Central Device C,

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

                              case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:

                               

                                      Advreport= *(CYBLE_GAPC_ADV_REPORT_T*) eventParam;

                                 

                                      //Checking for

                                      if(Advreport.peerBdAddr[1]==0xD0 && Advreport.peerBdAddr[2]==0x36  && Advreport.peerBdAddr[3]==0x28  &&

                                      Advreport.peerBdAddr[4]==0x00 && Advreport.peerBdAddr[5]==0x0A)            // checking for central periphreal Device B

                                      {

                                              

                                               if(Advreport.dataLen!=0)

                                            {

                                             RSSI=Advreport.rssi;         // central periphreal Device B rssi value

                                            printf("\r\n RSSI value of device central-peripheral is %d \r\n",RSSI);

                                             val[0]=Advreport.data[0];  //Advreport.data will contains the peripheral Device A  rssi value

                               

                                              y = ((int)val[0]) - 255;

                                              printf("\r\n RSSI value of device B %d \r\n",y);

                                                                 }

                               

                                        }

                              break;

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

                               

                              Thanks,

                              P Yugandhar.