BLE GAP Example Nucleo IDB0XA1

Dependencies:   BLE_API X_NUCLEO_IDB0XA1 mbed

Fork of BLE_GAP_Example by Bluetooth Low Energy

Revision:
14:6892af4291f1
Parent:
13:827dd2b32bb8
--- a/main.cpp	Thu Apr 02 21:16:43 2015 +0000
+++ b/main.cpp	Fri Dec 11 13:13:09 2015 +0000
@@ -1,48 +1,57 @@
 // Headers necessary for mbed and BLE device mode
 #include "mbed.h"
-#include "BLEDevice.h"
+#include "ble/BLE.h"
+#include "ble/Gap.h"
+#include "ble/services/BatteryService.h"
+#include "ble/services/DeviceInformationService.h"
 
-// BLE object
-BLEDevice ble;
+BLE  ble;
+Serial UART(SERIAL_TX, SERIAL_RX); // TX PA_2 , RX PA_3
+
+/* We can arbiturarily choose the GAPButton service UUID to be 0xAA00
+ * as long as it does not overlap with the UUIDs defined here:
+ * https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx */
+#define GAPButtonUUID 0xAA00
+static uint16_t uuid16_list[] = {GAPButtonUUID , 0x0000};
 
 // Optional: Device Name, add for human read-ability
-//const static char     DEVICE_NAME[]        = "ChangeMe!!"; // Optional: device name
-
-// You have up to 26 bytes of advertising data to use.
-const static uint8_t AdvData[] = {0x01,0x02,0x03,0x04,0x05};   // example of hex data
-//const static uint8_t AdvData[] = {"ChangeThisData"};         // example of character data
+ static char     DEVICE_NAME[] = "CESA BLE 4.0"; // Optional: device name
 
 // Optional: Restart advertising when phone app disconnects
-void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
+void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
 {
-    ble.startAdvertising();
+    ble.gap().startAdvertising();
 }
 
+
 // main program
 int main(void)
 {
+    UART.baud(115200); // Set BuadRate
+    
     // Initialize BLE baselayer, always do this first!
     ble.init();
 
     // Optional: add callback for disconnection
-    // ble.onDisconnection(disconnectionCallback);
+    ble.gap().onDisconnection(disconnectionCallback);
 
     // Sacrifice 3B of 31B to Advertising Flags
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
-    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
-
-    // Sacrifice 2B of 31B to AdvType overhead, rest goes to AdvData array you define
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData));
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
 
-    // Optional: Add name to device
-    //ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
-
+    // Put the device name in the advertising payload
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
+    
+    
+    ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
     // Set advertising interval. Longer interval = longer battery life
-    ble.setAdvertisingInterval(100); // 100ms, set as percentage of a second
-    ble.startAdvertising();
+    ble.gap().setAdvertisingInterval(100); // 100ms, set as percentage of a second
+    ble.gap().startAdvertising();
 
     // Infinite loop waiting for BLE events
-    for (;;) {
-        ble.waitForEvent(); // this saves battery while waiting for callback events
+    while(1)
+    {
+      ble.waitForEvent(); // this saves battery while waiting for callback events
     }
 }
+