Ble Demo with Raspberry PI

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_DEMO_SPI_HARDCODE by HM_IOT_Demo

Revision:
17:2e0273d799e2
Parent:
16:5bd717644078
Child:
18:0eefac249a4b
--- a/main.cpp	Tue Oct 10 09:42:29 2017 +0000
+++ b/main.cpp	Thu Oct 12 09:07:57 2017 +0000
@@ -33,7 +33,7 @@
            params->peerAddr[5], params->peerAddr[4], params->peerAddr[3], params->peerAddr[2], params->peerAddr[1], params->peerAddr[0],
            params->rssi, params->isScanResponse, params->type, params->advertisingData);
         //if (params->peerAddr[0] == 0x5A){ // 0x2F for red bear1.5 /* !ALERT! Alter this filter to suit your device. */
-        if (params->peerAddr[0] == 0x5B){ // 0x2F for red bear1.5 /* !ALERT! Alter this filter to suit your device. */
+        if (params->peerAddr[0] == 0xE5){ // 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],
@@ -71,7 +71,7 @@
 void characteristicDiscoveryCallback(const DiscoveredCharacteristic *characteristicP) {
     pc.printf("  C UUID-%x valueAttr[%u] props[%x]\r\n", characteristicP->getUUID().getShortUUID(), characteristicP->getValueHandle(), (uint8_t)characteristicP->getProperties().broadcast());
     
-    if (characteristicP->getUUID().getShortUUID() == 0xffe9) { /* !ALERT! Alter this filter to suit your device. */
+    if (characteristicP->getUUID().getShortUUID() == 0xec0e) { /* !ALERT! Alter this filter to suit your device. */
        lightCharacteristic = *characteristicP;
        pc.printf("Matched char UUID\r\n");
        printf("Conn Handle = %dand %d \r\n",characteristicP->getConnectionHandle(), lightCharacteristic.getConnectionHandle());
@@ -153,7 +153,20 @@
     }
     printf("\r\n");
 }
-
+void triggerRead(const GattReadCallbackParams *response)
+{
+    printf("reading data : \r\n");
+   // if (response->handle == GattCharacteristic.getValueHandle()) 
+  //  if (response->handle == characteristicP->getValueHandle())
+    {
+        printf("triggerToggledWrite: handle %u, offset %u, len %u\r\n", response->handle, response->offset, response->len);
+        for (unsigned index = 0; index < response->len; index++) 
+        {
+            printf("%c[%02x]", response->data[index], response->data[index]);
+        }
+        printf("\r\n");
+    }
+}
 
 /**
  * Callback triggered when the ble initialization process has finished
@@ -173,6 +186,7 @@
     ble.gap().setScanParams(1000, 800);
     ble.gap().startScan(advertisementCallback);
     //ble.gattClient().onHVX(hvxCallback);
+     ble.gattClient().onDataRead(triggerRead);
 
 }