Using nRF52 as Line Beacon

Dependencies:   mbed-os

Fork of BLE_GAP_Example by Bluetooth Low Energy

Revision:
16:836921833959
Parent:
15:7e06fce6e4f8
diff -r 7e06fce6e4f8 -r 836921833959 main.cpp
--- a/main.cpp	Tue Jan 12 12:00:16 2016 +0000
+++ b/main.cpp	Wed Apr 12 18:46:52 2017 +0000
@@ -13,16 +13,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 #include "mbed.h"
 #include "ble/BLE.h"
 
 /* Optional: Device Name, add for human read-ability */
-const static char     DEVICE_NAME[] = "ChangeMe!!";
+const static char     DEVICE_NAME[] = "Line Beacon 001";                                          /* Name it */
+
 
-/* 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 */
+const static uint8_t AdvServiceUUIDs[] = { 0x6F, 0xFE };
+const static uint8_t AdvData[] = { 0x6F, 0xFE, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x00 };  /* Replace 0xFF, 0xFF, 0xFF, 0xFF, 0xFF to your bot's HWID */
+//const static uint8_t AdvDataFrameType[] = { 0x02 };
+//const static uint8_t AdvDataHWID[] = { 0x02, 0x01, 0x02, 0xC5, 0x72, 0x10 };
+//const static uint8_t AdvDataMeasuredTxPower[] = { 0x7F };
+//const static uint8_t AdvDataDeviceMessage[] = { 0x00 };
 
 /* Optional: Restart advertising when peer disconnects */
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
@@ -37,9 +41,9 @@
     /* Avoid compiler warnings */
     (void) ble;
     (void) error;
-    
+
     /* Initialization error handling should go here */
-}    
+}
 
 /**
  * Callback triggered when the ble initialization process has finished
@@ -59,7 +63,7 @@
     if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
         return;
     }
-    
+
     /* Set device name characteristic data */
     ble.gap().setDeviceName((const uint8_t *) DEVICE_NAME);
 
@@ -71,14 +75,17 @@
     ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
 
     /* Sacrifice 2B of 31B to AdvType overhead, rest goes to AdvData array you define */
-    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, AdvData, sizeof(AdvData));
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, AdvServiceUUIDs, sizeof(AdvServiceUUIDs));
+
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, AdvServiceUUIDs, sizeof(AdvServiceUUIDs));
 
     /* Optional: Add name to device */
-    //ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SERVICE_DATA, AdvData, sizeof(AdvData));
+    //ble.gap().setAdvertisingData((const uint8_t *)AdvServiceUUIDs, (const uint8_t *)AdvData);
 
     /* Set advertising interval. Longer interval == longer battery life */
     ble.gap().setAdvertisingInterval(100); /* 100ms */
-
+    
     /* Start advertising */
     ble.gap().startAdvertising();
 }
@@ -86,7 +93,7 @@
 int main(void)
 {
     BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
- 
+
     /* Initialize BLE baselayer, always do this first! */
     ble.init(bleInitComplete);