A simple demo that directly uses BLE library to define service and characteristics

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate by Bluetooth Low Energy

Files at this revision

API Documentation at this revision

Comitter:
nebgnahz
Date:
Wed Oct 22 17:08:57 2014 +0000
Parent:
49:14b2df099dfc
Commit message:
use random generated UUID from http://www.itu.int/ITU-T/asn1/uuid.html

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 14b2df099dfc -r 4c02add9abba main.cpp
--- a/main.cpp	Wed Oct 22 05:47:25 2014 +0000
+++ b/main.cpp	Wed Oct 22 17:08:57 2014 +0000
@@ -4,9 +4,20 @@
 BLEDevice  ble;
 DigitalOut led1(LED1);
 
-const static char     DEVICE_NAME[]        = "Nordic";
-// we only broadcast a single service
-static const uint16_t uuid16_list[]        = {0xFFFF};
+const uint8_t LED1_UUID[LENGTH_OF_LONG_UUID] = {
+    0xfb, 0x71, 0xbc, 0xc0, 0x5a, 0x0c, 0x11, 0xe4,
+    0x91, 0xae, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b
+};
+const uint8_t BUTTON_UUID[LENGTH_OF_LONG_UUID] = {
+    0x7a, 0x77, 0xbe, 0x20, 0x5a, 0x0d, 0x11, 0xe4,
+    0xa9, 0x5e, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b
+};
+const uint8_t TEST_SERVICE_UUID[LENGTH_OF_LONG_UUID] = {
+    0xb0, 0xbb, 0x58, 0x20, 0x5a, 0x0d, 0x11, 0xe4,
+    0x93, 0xee, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b
+};
+
+const static char DEVICE_NAME[] = "Nordic";
 static volatile bool is_button_pressed = false;
 static volatile uint16_t led1_handler;
 
@@ -49,20 +60,23 @@
     // o led1 characteristics, you can write from the phone to control led1
     // o button characteristics, you can read and get notified
     GattCharacteristic led1_characteristics(
-        0xFF00, &led_state, sizeof(led_state), sizeof(led_state),
+        LED1_UUID, &led_state, sizeof(led_state), sizeof(led_state),
         GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ |
         GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE);
     led1_handler = led1_characteristics.getValueAttribute().getHandle();
 
     GattCharacteristic button_characteristics(
-        0xFF01, &button_state, sizeof(button_state), sizeof(button_state),
+        BUTTON_UUID, &button_state, sizeof(button_state), sizeof(button_state),
         GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | 
         GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
     
+    const uint8_t TEST_SERVICE_UUID[LENGTH_OF_LONG_UUID] = {
+        0xb0, 0xbb, 0x58, 0x20, 0x5a, 0x0d, 0x11, 0xe4,
+        0x93, 0xee, 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b};
     GattCharacteristic *charTable[] = {&led1_characteristics, &button_characteristics};
-    GattService testService(0xFFFF, charTable,
+    GattService testService(TEST_SERVICE_UUID, charTable,
                             sizeof(charTable) / sizeof(GattCharacteristic *));
-    
+
     // BLE setup, mainly we add service and callbacks
     ble.init();
     ble.addService(testService);
@@ -71,9 +85,7 @@
     
     // setup advertising
     ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED |
-                                     GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS,
-                                     (uint8_t *)uuid16_list, sizeof(uuid16_list));
+                                     GapAdvertisingData::LE_GENERAL_DISCOVERABLE);                      
     ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME,
                                      (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
     ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
@@ -90,4 +102,4 @@
             ble.waitForEvent();
         }
     }
-}
+}
\ No newline at end of file