5 Replies Latest reply on Mar 12, 2020 6:24 AM by PY_21

    hello sir ,

    atga_4655031

      my questions is

      my BLE device is central and peripheral mode.

      1) first case- BLE device is central and my android mobile is peripheral.

      so peripheral start advertising packet. so my central device is store the peripheral packet in some array.

      then i check in data base is that my mobile device mac address match to database then communicate.otherwise disconnect.

       

      2)second case -how ble device switch from central to peripheral.

       

      please solve my issues.

       

       

      regards,

      Atul

       

      atulg@iotech.biz

        • 1. Re: hello sir ,
          PY_21

          Hello,


          1. Please refer to the Day010_Observer and Day013_Client_Server projects from the GitHub. In this example projects, initially 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).

          At the central device, in scan progress result event(CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT), you can check for the particular Advertising device address and can make a connection( Day013_Client_Server project will give the information on connection between two devices).

           

          2. To configure PSoC4 BLE in both Central and Peripheral GAP role you can refer to the Day012_Central_Peripheral example project from the GitHub. In this project, when the device is acting as central, it can scan and connect to peer device which is advertising. When acting as peripheral it can advertise and other Central can connect to the PSoC4 BLE.

           

          Please let me know if this helps.

           

          Thanks,
          P Yugandhar.

          • 2. Re: hello sir ,
            atga_4655031

            hello sir,

             

            thanks sir givening information.

            i have one doubt please clear this.

            how the central device is scanning the advertising packet.

            in advetisng packet so many information how central is know that device is all ready used before.

            • 3. Re: hello sir ,
              atga_4655031

              hello sir,

              without UART it is communication possible between central and peripheral.

              • 4. Re: hello sir ,
                PY_21

                Hello,

                1. Central device is a device that scans for advertisements from GAP Peripherals and establishes a connection with them. When PSoC4 BLE is configured in GAP Central role then after scan start, CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT will occurs when it receives any advertisement packet or scan response packet from the peer devices. CYBLE_GAPC_ADV_REPORT_T is returned as the event parameter and this structure CYBLE_GAPC_ADV_REPORT_T will contains the advertisement report of the peripheral devices. This Advertisement report will contains the below data.

                *****************************************
                /** Advertisement report received by GAP Central */
                typedef struct
                {
                /** Advertisement event type
                     - Connectable undirected advertising = 0x00
                     - Connectable directed advertising = 0x01
                      - Scannable undirected advertising = 0x02
                      - Non connectable undirected advertising = 0x03
                      - Scan Response = 0x04
                     */
                CYBLE_GAPC_ADV_EVENT_T  eventType;

                /** bd address type of the device advertising.
                  - CYBLE_GAP_ADDR_TYPE_PUBLIC
                  - CYBLE_GAP_ADDR_TYPE_RANDOM
                  - CYBLE_GAP_ADDR_TYPE_PUBLIC_RPA
                  - CYBLE_GAP_ADDR_TYPE_RANDOM_RPA
                    */
                    uint8           peerAddrType;

                /** Public Device Address or Random Device Address for
                    each device which responded to scanning. */
                    uint8*         peerBdAddr;

                /** length of the data for each device that responded to scanning */
                    uint8           dataLen;     

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

                /** Rssi of the responding device.
                     * Range: -85 <= N <= 0
                     * Units: dBm */
                    int8         rssi;

                } CYBLE_GAPC_ADV_REPORT_T;
                *****************************************

                 

                2. Yes, you can make communication between central and peripheral without UART. In the projects, UART is used for displaying the Advertisement packets information of all the devices, sending the controlled commands etc. Please refer to the projects for more information.

                 

                Please let me know if you have any questions.

                 

                Thanks,
                P Yugandhar.

                • 5. Re: hello sir ,
                  PY_21

                  Hello,

                   

                  At the central device, in CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT event, you can check for the particular Advertising device address and make a connection as shown in below code.

                   

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

                         case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:

                   

                                  scanReport=  *(CYBLE_GAPC_ADV_REPORT_T*)eventParam;
                                
                                  if(scanReport.peerBdAddr[0] == 0x01 && scanReport.peerBdAddr[1] == 0x02 && scanReport.peerBdAddr[2] == 0x03 && scanReport.peerBdAddr[3] == 0x04 && scanReport.data[4] == 0x05 && scanReport.data[5] == 0x0a)
                                  {
                                      printf("peer address:\r\n");
                                     for(i=0;i<CYBLE_GAP_BD_ADDR_SIZE;i++)
                                      {
                                          peerDeviceAddr.bdAddr[i]=scanReport.peerBdAddr[i];
                                          printf("%2.2x",scanReport.peerBdAddr[CYBLE_GAP_BD_ADDR_SIZE-1-i]);
                                      }
                                      printf("\r\n");
                                      deviceDetected=TRUE;
                                      CyBle_GapcStopScan();
                                  }
                              break;

                          case CYBLE_EVT_GAPC_SCAN_START_STOP:

                                  if(CyBle_GetState()==CYBLE_STATE_DISCONNECTED)
                                  {   
                                      printf("Stop scanning:\r\n");
                                      if(deviceDetected==TRUE)
                                      {
                                          apiResult=CyBle_GapcConnectDevice(&peerDeviceAddr);
                                          if(apiResult==CYBLE_ERROR_OK)
                                          {
                                              printf("success\r\n");
                                          }
                                          else
                                          {
                                              printf("connection failed:%x\r\n",apiResult);
                                          }
                                          deviceDetected=FALSE;  
                                      }
                                  }
                              break;

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

                   

                  Thanks,
                  P Yugandhar.