BLE_GAP_iBeacon_Example (Nucleo and ID0XA1)

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 12:54:13 2015 +0000
Parent:
13:827dd2b32bb8
Commit message:
BLE_GAP_iBeacon_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
diff -r 827dd2b32bb8 -r 2b504fd9006c BLE_API.lib
--- a/BLE_API.lib	Thu Apr 02 21:16:43 2015 +0000
+++ b/BLE_API.lib	Fri Dec 11 12:54:13 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
diff -r 827dd2b32bb8 -r 2b504fd9006c X_NUCLEO_IDB0XA1.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDB0XA1.lib	Fri Dec 11 12:54:13 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/X_NUCLEO_IDB0XA1/#d22cc4715b0c
diff -r 827dd2b32bb8 -r 2b504fd9006c main.cpp
--- a/main.cpp	Thu Apr 02 21:16:43 2015 +0000
+++ b/main.cpp	Fri Dec 11 12:54:13 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/iBeacon.h"
 
-// BLE object
-BLEDevice ble;
+BLE  ble;
+Serial UART(SERIAL_TX, SERIAL_RX); // TX PA_2 , RX PA_3
+
+InterruptIn int_external(PC_13);
+DigitalIn  Push_Button(PC_13,PullNone);
 
-// 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
+/**
+ * The Beacon payload has the following composition:
+ * 128-Bit / 16byte UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
+ * Major/Minor  = 0x1122 / 0x3344
+ * Tx Power     = 0xC8 = 200, 2's compliment is 256-200 = (-56dB)
+ *
+ * Note: please remember to calibrate your beacons TX Power for more accurate results.
+ */
+static const uint8_t uuid[] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF,
+                               0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0x00};
+uint16_t majorNumber = 1234;
+uint16_t minorNumber = 5678;
+uint16_t txPower     = 0xC8;
+    
+uint16_t count = 0;   
 
 // 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);
-
-    // Sacrifice 3B of 31B to Advertising Flags
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
-    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
-
+    ble.gap().onDisconnection(disconnectionCallback);
+    
     // Sacrifice 2B of 31B to AdvType overhead, rest goes to AdvData array you define
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData));
-
-    // Optional: Add name to device
-    //ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
-
+    iBeacon(ble, uuid, majorNumber, minorNumber, txPower); //ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, Company, sizeof(Company));
     // 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
     }
-}
+}
\ No newline at end of file
diff -r 827dd2b32bb8 -r 2b504fd9006c nRF51822.lib
--- 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