BLE GAP Example Nucleo IDB0XA1

Dependencies:   BLE_API X_NUCLEO_IDB0XA1 mbed

Fork of BLE_GAP_Example by Bluetooth Low Energy

Files at this revision

API Documentation at this revision

Comitter:
anoney180133
Date:
Fri Dec 11 13:13:09 2015 +0000
Parent:
13:827dd2b32bb8
Commit message:
BLE GAP Example Nucleo with IDB0XA1

Changed in this revision

BLE_API.lib Show annotated file Show diff for this revision Revisions of this file
X_NUCLEO_IDB0XA1.lib 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
nRF51822.lib Show diff for this revision Revisions of this file
--- a/BLE_API.lib	Thu Apr 02 21:16:43 2015 +0000
+++ b/BLE_API.lib	Fri Dec 11 13:13:09 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#8c645f5694b2
+http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#a097e1be76f4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDB0XA1.lib	Fri Dec 11 13:13:09 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/X_NUCLEO_IDB0XA1/#d22cc4715b0c
--- 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
     }
 }
+
--- a/nRF51822.lib	Thu Apr 02 21:16:43 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#bdc690669431