BLE_GAP_iBeacon_Example (Nucleo and ID0XA1)

Dependencies:   BLE_API X_NUCLEO_IDB0XA1 mbed

Fork of BLE_GAP_Example by Bluetooth Low Energy

Committer:
anoney180133
Date:
Fri Dec 11 12:54:13 2015 +0000
Revision:
14:2b504fd9006c
Parent:
13:827dd2b32bb8
BLE_GAP_iBeacon_Example Nucleo with IDB0XA1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 1:0692bee84264 1 // Headers necessary for mbed and BLE device mode
mbedAustin 0:5375be4301ed 2 #include "mbed.h"
anoney180133 14:2b504fd9006c 3 #include "ble/BLE.h"
anoney180133 14:2b504fd9006c 4 #include "ble/Gap.h"
anoney180133 14:2b504fd9006c 5 #include "ble/services/iBeacon.h"
mbedAustin 0:5375be4301ed 6
anoney180133 14:2b504fd9006c 7 BLE ble;
anoney180133 14:2b504fd9006c 8 Serial UART(SERIAL_TX, SERIAL_RX); // TX PA_2 , RX PA_3
anoney180133 14:2b504fd9006c 9
anoney180133 14:2b504fd9006c 10 InterruptIn int_external(PC_13);
anoney180133 14:2b504fd9006c 11 DigitalIn Push_Button(PC_13,PullNone);
mbedAustin 0:5375be4301ed 12
anoney180133 14:2b504fd9006c 13 /**
anoney180133 14:2b504fd9006c 14 * The Beacon payload has the following composition:
anoney180133 14:2b504fd9006c 15 * 128-Bit / 16byte UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
anoney180133 14:2b504fd9006c 16 * Major/Minor = 0x1122 / 0x3344
anoney180133 14:2b504fd9006c 17 * Tx Power = 0xC8 = 200, 2's compliment is 256-200 = (-56dB)
anoney180133 14:2b504fd9006c 18 *
anoney180133 14:2b504fd9006c 19 * Note: please remember to calibrate your beacons TX Power for more accurate results.
anoney180133 14:2b504fd9006c 20 */
anoney180133 14:2b504fd9006c 21 static const uint8_t uuid[] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF,
anoney180133 14:2b504fd9006c 22 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0x00};
anoney180133 14:2b504fd9006c 23 uint16_t majorNumber = 1234;
anoney180133 14:2b504fd9006c 24 uint16_t minorNumber = 5678;
anoney180133 14:2b504fd9006c 25 uint16_t txPower = 0xC8;
anoney180133 14:2b504fd9006c 26
anoney180133 14:2b504fd9006c 27 uint16_t count = 0;
mbedAustin 1:0692bee84264 28
mbedAustin 13:827dd2b32bb8 29 // Optional: Restart advertising when phone app disconnects
anoney180133 14:2b504fd9006c 30 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
mbedAustin 13:827dd2b32bb8 31 {
anoney180133 14:2b504fd9006c 32 ble.gap().startAdvertising();
mbedAustin 8:5442739198ec 33 }
mbedAustin 8:5442739198ec 34
mbedAustin 1:0692bee84264 35 // main program
mbedAustin 1:0692bee84264 36 int main(void)
mbedAustin 0:5375be4301ed 37 {
anoney180133 14:2b504fd9006c 38 UART.baud(115200); // Set BuadRate
anoney180133 14:2b504fd9006c 39
mbedAustin 1:0692bee84264 40 // Initialize BLE baselayer, always do this first!
mbedAustin 1:0692bee84264 41 ble.init();
mbedAustin 13:827dd2b32bb8 42
mbedAustin 11:c9c0c4586c5f 43 // Optional: add callback for disconnection
anoney180133 14:2b504fd9006c 44 ble.gap().onDisconnection(disconnectionCallback);
anoney180133 14:2b504fd9006c 45
mbedAustin 1:0692bee84264 46 // Sacrifice 2B of 31B to AdvType overhead, rest goes to AdvData array you define
anoney180133 14:2b504fd9006c 47 iBeacon(ble, uuid, majorNumber, minorNumber, txPower); //ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, Company, sizeof(Company));
mbedAustin 1:0692bee84264 48 // Set advertising interval. Longer interval = longer battery life
anoney180133 14:2b504fd9006c 49 ble.gap().setAdvertisingInterval(100); // 100ms, set as percentage of a second
anoney180133 14:2b504fd9006c 50 ble.gap().startAdvertising();
mbedAustin 1:0692bee84264 51
mbedAustin 1:0692bee84264 52 // Infinite loop waiting for BLE events
anoney180133 14:2b504fd9006c 53 while(1)
anoney180133 14:2b504fd9006c 54 {
anoney180133 14:2b504fd9006c 55 ble.waitForEvent(); // this saves battery while waiting for callback events
mbedAustin 1:0692bee84264 56 }
anoney180133 14:2b504fd9006c 57 }