Send notification to pi from ble nano using ButtonService

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_notifications by Zachary Newman

Files at this revision

API Documentation at this revision

Comitter:
nkosarek
Date:
Wed Apr 19 01:47:36 2017 +0000
Parent:
13:d4448d59ab69
Commit message:
Working code to send one byte via notification is commented out. Attempt to send 16 bytes is currently compiled.

Changed in this revision

ButtonService.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ButtonService.h	Wed Apr 19 01:22:46 2017 +0000
+++ b/ButtonService.h	Wed Apr 19 01:47:36 2017 +0000
@@ -30,8 +30,10 @@
         ble.gattServer().addService(buttonService);
     }
 
-    void updateButtonState(uint8_t newState) {
-        ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(uint8_t));
+    //void updateButtonState(uint8_t newState) {
+    void updateButtonState(uint8_t *newState) {
+        //ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(uint8_t));
+        ble.gattServer().write(buttonState.getValueHandle(), newState, sizeof(uint8_t)*16);
     }
 
 private:
--- a/main.cpp	Wed Apr 19 01:22:46 2017 +0000
+++ b/main.cpp	Wed Apr 19 01:47:36 2017 +0000
@@ -92,7 +92,11 @@
 int main(void)
 {
     pc.printf("entering main!! \r\n");
-    uint8_t counter = 0;
+    //uint8_t counter = 65; //'A'
+    uint8_t counter[16] = {65, 65, 65, 65, 65,
+                           65, 65, 65, 65, 65,
+                           65, 65, 65, 65, 65,
+                           0};
 
     BLE &ble = BLE::Instance();
     ble.init(bleInitComplete);
@@ -106,9 +110,13 @@
     while (true) {
         pc.printf("loop!\r\n");
         if(isThereAConnection) {
-            pc.printf("sending Notification: %d\r\n", counter);
+            //pc.printf("sending Notification: %d\r\n", counter);
+            pc.printf("sending Notification: %d\r\n", counter[0]);
             buttonServicePtr->updateButtonState(counter);
-            counter++;
+            //counter++;
+            for( int i = 0; i < 16; i++ ) {
+                counter[i] = counter[i]+1;
+            }
         } else {
             //
         }