AltBeacon program for embedded BLE. This program demonstrates how to set up a BLE device to broadcast AltBLE compatible data. Please see the official website for more details. https://github.com/AltBeacon/spec and http://altbeacon.org/

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_AltBeacon by Austin Blackstone

Description

AltBeacon is an open beacon standard developed by Roving Networks. AltBeacons an alternative to the closed sourced and heavily licensed iBeacon standard.

For full details please see the AltBeacon repository

Files at this revision

API Documentation at this revision

Comitter:
andresag
Date:
Tue Jan 12 11:34:09 2016 +0000
Parent:
1:cc428f427838
Commit message:
Update example to latest BLE API.

Changed in this revision

AltBeaconService.h Show annotated file Show diff for this revision Revisions of this file
BLE_API.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nRF51822.lib Show annotated file Show diff for this revision Revisions of this file
diff -r cc428f427838 -r 6ec277483638 AltBeaconService.h
--- a/AltBeaconService.h	Fri Mar 20 21:10:12 2015 +0000
+++ b/AltBeaconService.h	Tue Jan 12 11:34:09 2016 +0000
@@ -16,7 +16,7 @@
 #ifndef __BLE_ALTBEACON_SERVICE_H__
 #define __BLE_ALTBEACON_SERVICE_H__
 
-#include "BLEDevice.h"
+#include "ble/BLE.h"
 
 /**
 * @class AltBeaconService
@@ -27,8 +27,8 @@
 {
 public:
     /**
-    * @param[ref] _ble
-    *               BLEDevice object for the underlying controller.
+    * @param[in] _ble
+    *               BLE object for the underlying controller.
     * @param[in] mfgID
     *               The beacon device manufacturer's company identifier code. 
     *               Usually this will coorespond to the companies BLE SIG assigned number.
@@ -43,27 +43,30 @@
     * @param[in] mfgReserved
     *               Used for special manufacturer data. Defaults to 0x00 if not specified.
     */
-    AltBeaconService(BLEDevice &_ble, uint16_t mfgID, uint8_t beaconID[20], int8_t refRSSI, uint8_t mfgReserved = 0x00):
+    AltBeaconService(BLE &_ble, uint16_t mfgID, uint8_t beaconID[20], int8_t refRSSI, uint8_t mfgReserved = 0x00):
         ble(_ble)
     {
-        data.mfgID = ((mfgID<<8) | (mfgID >>8));
-        if(refRSSI > 0){refRSSI = 0;} // refRSSI can only be 0 to -127, smash everything above 0 to zero
-        data.refRSSI = refRSSI;
-        data.beaconCode = 0xACBE;
+        /* refRSSI can only be 0 to -127, smash everything above 0 to zero */
+        if (refRSSI > 0) {
+            refRSSI = 0;
+        }
+        data.mfgID       = ((mfgID<<8) | (mfgID >>8));
+        data.refRSSI     = refRSSI;
+        data.beaconCode  = 0xACBE;
         data.mfgReserved = mfgReserved;
 
-        // copy across beacon ID
-        for(int x=0; x<sizeof(data.beaconID); x++) {
+        /* copy across beacon ID */
+        for(int x = 0; x < sizeof(data.beaconID); x++) {
             data.beaconID[x] = beaconID[x];
         }
 
-        // Set up alt beacon
-        ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
-        // Generate the 0x1BFF part of the Alt Prefix
-        ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw));
+        /* Set up alt beacon */
+        ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+        /* Generate the 0x1BFF part of the Alt Prefix */
+        ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw));
 
-        // Set advertising type
-        ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
+        /* Set advertising type */
+        ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
     }
 
 public:
@@ -79,8 +82,8 @@
     } data;
 
 private:
-    BLEDevice &ble;
+    BLE &ble;
 
 };
 
-#endif //__BLE_ALTBEACON_SERVICE_H__
+#endif /* __BLE_ALTBEACON_SERVICE_H__ */
diff -r cc428f427838 -r 6ec277483638 BLE_API.lib
--- a/BLE_API.lib	Fri Mar 20 21:10:12 2015 +0000
+++ b/BLE_API.lib	Tue Jan 12 11:34:09 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#d87182a62c1b
+http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#bfc5b9b6ecf5
diff -r cc428f427838 -r 6ec277483638 main.cpp
--- a/main.cpp	Fri Mar 20 21:10:12 2015 +0000
+++ b/main.cpp	Tue Jan 12 11:34:09 2016 +0000
@@ -16,6 +16,7 @@
 
 #include "mbed.h"
 #include "AltBeaconService.h"
+#include "ble/BLE.h"
 
 /**
  * For this demo application, populate the beacon advertisement payload
@@ -25,8 +26,6 @@
  *  Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18
  */
 
-BLEDevice ble;
-
 /**
  * The AltBeacon requires a manufacturer ID, and a Beacon ID
  * the first 16 bytes of the BeaconID should be a UUID and the remaining
@@ -35,25 +34,58 @@
  * Note: please remember to calibrate your beacon
  * RSSI for more accurate results.
  */
-uint8_t beaconID[] = {  0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
-                        0x10,0x11,0x12,0x13,0x14,0x15,0x00,0x01,0x00,0x02 };
-uint16_t manufacturerID = 0x5900; //Nordic SIG ID
-int8_t rssi = -122;
+uint8_t beaconID[]      = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
+                           0x10,0x11,0x12,0x13,0x14,0x15,0x00,0x01,0x00,0x02};
+uint16_t manufacturerID = 0x5900; /* Nordic SIG ID */
+int8_t   rssi           = -122;
+
+AltBeaconService *altBeaconServicePtr;
+
+/**
+ * This function is called when the ble initialization process has failed
+ */
+void onBleInitError(BLE &ble, ble_error_t error)
+{
+    /* Initialization error handling should go here */
+}
 
+/**
+ * Callback triggered when the ble initialization process has finished
+ */
+void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
+{
+    BLE&        ble   = params->ble;
+    ble_error_t error = params->error;
+
+    if (error != BLE_ERROR_NONE) {
+        /* In case of error, forward the error handling to onBleInitError */
+        onBleInitError(ble, error);
+        return;
+    }
+
+    /* Ensure that it is the default instance of BLE */
+    if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
+        return;
+    }
+
+    /* Initialize AltBeacon */
+    altBeaconServicePtr =new AltBeaconService(ble, manufacturerID, beaconID, rssi);
+
+    /* Set advertising time */
+    ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
+    
+    /* Start advertising */
+    ble.startAdvertising();
+}
 
 int main(void)
 {
-    // Initialize BLE baselayer
-    ble.init();
-
-    // Initialize AltBeacon
-    AltBeaconService altbeacon(ble, manufacturerID, beaconID, rssi);
+    BLE& ble = BLE::Instance();
 
-    // Set advertising time
-    ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
-    ble.startAdvertising();
+    /* Initialize BLE baselayer */ 
+    ble.init(bleInitComplete);
 
-    while(1) {
-        ble.waitForEvent(); // allows or low power operation
+    while(true) {
+        ble.waitForEvent(); /* Allow low power operation */
     }
 }
diff -r cc428f427838 -r 6ec277483638 mbed.bld
--- a/mbed.bld	Fri Mar 20 21:10:12 2015 +0000
+++ b/mbed.bld	Tue Jan 12 11:34:09 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c
\ No newline at end of file
diff -r cc428f427838 -r 6ec277483638 nRF51822.lib
--- a/nRF51822.lib	Fri Mar 20 21:10:12 2015 +0000
+++ b/nRF51822.lib	Tue Jan 12 11:34:09 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#bc524269c7c1
+http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#3cc0718d98d0