Demo Glucose Service

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate by Bluetooth Low Energy

BLE_Glucose_demo implements the Glucose Service which enables a collector device to connect and interact with.

There is a brief sample code edited with Android Studio for demo this BLE_Glucose_demo example, and it is public on github, everyone can clone it by this URL: https://github.com/Marcomissyou/BluetoothLeGlucose.git. It is convenient for you to development your BLE idea.

There is also provided apk file so you can download and install it directly then demo this code, but make sure your Android phone supports Bluetooth 4.0. /media/uploads/Marcomissyou/bleglucoseservice.apk

Revision:
9:5d693381e883
Parent:
8:49d8ee0aac11
Child:
10:2436164b692e
--- a/main.cpp	Tue Jun 10 11:03:03 2014 +0100
+++ b/main.cpp	Tue Jun 10 11:21:56 2014 +0100
@@ -20,7 +20,17 @@
 BLEPeripheral  ble;                 /* BLE radio driver */
 
 DigitalOut led1(LED1);
-Serial     pc(USBTX, USBRX);
+
+#define NEED_CONSOLE_OUTPUT 0 /* Set this if you need debug messages on the console;
+                               * it will have an impact on code-size and power
+                               * consumption. */
+
+#if NEED_CONSOLE_OUTPUT
+Serial  pc(USBTX, USBRX);
+#define DEBUG(...) { pc.printf(__VA_ARGS__); }
+#else
+#define DEBUG(...) /* nothing */
+#endif /* #if NEED_CONSOLE_OUTPUT */
 
 /* Battery Level Service */
 uint8_t            batt      = 72; /* Battery level */
@@ -62,34 +72,34 @@
 
 void timeoutCallback(void)
 {
-    pc.printf("Advertising Timeout!\n\r");
+    DEBUG("Advertising Timeout!\n\r");
     // Restart the advertising process with a much slower interval,
     // only start advertising again after a button press, etc.
 }
 
 void connectionCallback(void)
 {
-    pc.printf("Connected!\n\r");
+    DEBUG("Connected!\n\r");
 }
 
 void disconnectionCallback(void)
 {
-    pc.printf("Disconnected!\n\r");
-    pc.printf("Restarting the advertising process\n\r");
+    DEBUG("Disconnected!\n\r");
+    DEBUG("Restarting the advertising process\n\r");
     ble.startAdvertising();
 }
 
 void updatesEnabledCallback(uint16_t charHandle)
 {
     if (charHandle == hrmRate.getHandle()) {
-        pc.printf("Heart rate notify enabled\n\r");
+        DEBUG("Heart rate notify enabled\n\r");
     }
 }
 
 void updatesDisabledCallback(uint16_t charHandle)
 {
     if (charHandle == hrmRate.getHandle()) {
-        pc.printf("Heart rate notify disabled\n\r");
+        DEBUG("Heart rate notify disabled\n\r");
     }
 }
 
@@ -110,7 +120,7 @@
     ble.onUpdatesDisabled(updatesDisabledCallback);
 
     /* Initialise the nRF51822 */
-    pc.printf("Initialising the nRF51822\n\r");
+    DEBUG("Initialising the nRF51822\n\r");
     ble.init();
 
     /* Add BLE-Only flag and complete service list to the advertising data */
@@ -135,13 +145,11 @@
     ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
     ble.startAdvertising();
 
-    /* Wait until we are connected to a central device before updating
-     * anything */
-    pc.printf("Waiting for a connection ...");
+    /* Wait until we are connected to a central device before updating anything */
+    DEBUG("Waiting for a connection ...");
     while (!ble.getGapState().connected) {
         ble.waitForEvent();
     }
-    pc.printf("Connected!\n\r");
 
     /* Now that we're live, update the battery level characteristic, and
      * change the device manufacturer characteristic to 'mbed' */