Working Code

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_Central_Light_Demo by HM_IOT_Demo

Revision:
11:58d8a3129877
Parent:
10:5e5fa5bf77b5
Child:
12:cd54180657ee
--- a/main.cpp	Mon Jan 30 15:20:48 2017 +0000
+++ b/main.cpp	Tue Jan 31 04:10:34 2017 +0000
@@ -22,7 +22,9 @@
     uint8_t con_status =0;
      //0x51 for Magic light 
     //0x5A
-    if (params->peerAddr[0] == 0x51) { // 0x2F for red bear1.5 /* !ALERT! Alter this filter to suit your device. */
+    int i;
+    //for(i=0; i<2; i++){
+        if ((params->peerAddr[0] == 0x51) || (params->peerAddr[0] == 0x5A)) { // 0x2F for red bear1.5 /* !ALERT! Alter this filter to suit your device. */
        
            pc.printf("adv peerAddr[%02x %02x %02x %02x %02x %02x] rssi %d, isScanResponse %u, AdvertisementType %u\r\n",
            params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0],
@@ -31,12 +33,14 @@
            con_status = BLE::Instance().gap().connect(params->peerAddr, Gap::ADDR_TYPE_PUBLIC, NULL, NULL);
            pc.printf("Connection Status : %d\r\n",con_status);
            connect_status = 1;
-           BLE::Instance().gap().stopScan();
+           i++;
+           //BLE::Instance().gap().stopScan();
            
-    }else{
-        printf("Not Matched your device\r\n");
-        return;
-    }
+        }else{
+            printf("Not Matched your device\r\n");
+            return;
+        }
+    //}
  }
 
 void serviceDiscoveryCallback(const DiscoveredService *service) {
@@ -219,15 +223,15 @@
     wait(8.0);
     pc.printf("Start\n\r");
    // int options;
-    spiSlave.reply(191);
+    //spiSlave.reply(191);
     bleint();
     bufferSize = 0;
     while(1){
         //printf("loop\r\n");
-        if(!(connect_status && charDiscover))
+     //   if(!(connect_status && charDiscover))
             waitBleEvent();
             
-        if(spiSlave.receive()){
+    /*    if(spiSlave.receive()){
             // printf("Slave Read loop1\r\n");
             spiRX[bufferSize] = spiSlave.read();
             spiSlave.reply(spiRX[bufferSize]);
@@ -239,7 +243,7 @@
                 spiSlave.reply(0xAA);
             }
             
-        }
+        } */
         
         wait_us(15);
     }