Beacon demo for the BLE API using the nRF51822 native mode drivers

Dependencies:   BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1

Fork of BLE_iBeacon by Bluetooth Low Energy

Committer:
mbedAustin
Date:
Mon Dec 08 22:27:49 2014 +0000
Revision:
50:7bc38f01d2d3
Parent:
48:2f0f293a4966
Child:
53:f9ec2c7a47f5
Added comments to iBeacon structure for clarity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 0:7613d21e5974 1 /* mbed Microcontroller Library
ktownsend 0:7613d21e5974 2 * Copyright (c) 2006-2013 ARM Limited
ktownsend 0:7613d21e5974 3 *
ktownsend 0:7613d21e5974 4 * Licensed under the Apache License, Version 2.0 (the "License");
ktownsend 0:7613d21e5974 5 * you may not use this file except in compliance with the License.
ktownsend 0:7613d21e5974 6 * You may obtain a copy of the License at
ktownsend 0:7613d21e5974 7 *
ktownsend 0:7613d21e5974 8 * http://www.apache.org/licenses/LICENSE-2.0
ktownsend 0:7613d21e5974 9 *
ktownsend 0:7613d21e5974 10 * Unless required by applicable law or agreed to in writing, software
ktownsend 0:7613d21e5974 11 * distributed under the License is distributed on an "AS IS" BASIS,
ktownsend 0:7613d21e5974 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ktownsend 0:7613d21e5974 13 * See the License for the specific language governing permissions and
ktownsend 0:7613d21e5974 14 * limitations under the License.
ktownsend 0:7613d21e5974 15 */
ktownsend 0:7613d21e5974 16
ktownsend 0:7613d21e5974 17 #include "mbed.h"
Rohit Grover 32:7b7093b653a8 18 #include "BLEDevice.h"
ktownsend 0:7613d21e5974 19
mbedAustin 50:7bc38f01d2d3 20 /**
Rohit Grover 10:391c1acf4b9d 21 * For this demo application, populate the beacon advertisement payload
Rohit Grover 15:4e1b36b73213 22 * with 2 AD structures: FLAG and MSD (manufacturer specific data).
Rohit Grover 10:391c1acf4b9d 23 *
Rohit Grover 10:391c1acf4b9d 24 * Reference:
Rohit Grover 10:391c1acf4b9d 25 * Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18
Rohit Grover 10:391c1acf4b9d 26 */
ktownsend 0:7613d21e5974 27
mbedAustin 50:7bc38f01d2d3 28 BLEDevice ble;
mbedAustin 50:7bc38f01d2d3 29
mbedAustin 50:7bc38f01d2d3 30 /**
mbedAustin 50:7bc38f01d2d3 31 * The Beacon payload (encapsulated within the MSD advertising data structure)
mbedAustin 50:7bc38f01d2d3 32 * has the following composition:
mbedAustin 50:7bc38f01d2d3 33 * 128-Bit UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
mbedAustin 50:7bc38f01d2d3 34 * Major/Minor = 0000 / 0000
mbedAustin 50:7bc38f01d2d3 35 * Tx Power = C8 (-56dB)
mbedAustin 50:7bc38f01d2d3 36 */
mbedAustin 50:7bc38f01d2d3 37 const static uint8_t iBeaconPayload[] = {
mbedAustin 50:7bc38f01d2d3 38 0x4C, 0x00, // Company identifier code (0x004C == Apple)
mbedAustin 50:7bc38f01d2d3 39 0x02, // ID
mbedAustin 50:7bc38f01d2d3 40 0x15, // length of the remaining payload
mbedAustin 50:7bc38f01d2d3 41 0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, // location UUID
mbedAustin 50:7bc38f01d2d3 42 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61,
mbedAustin 50:7bc38f01d2d3 43 0x00, 0x00, // the major value to differentiate a location
mbedAustin 50:7bc38f01d2d3 44 0x00, 0x00, // the minor value to differentiate a location
mbedAustin 50:7bc38f01d2d3 45 0xC8 // 2's complement of the Tx power (-56dB)
mbedAustin 50:7bc38f01d2d3 46 };
Rohit Grover 10:391c1acf4b9d 47
ktownsend 0:7613d21e5974 48 int main(void)
ktownsend 0:7613d21e5974 49 {
mbedAustin 50:7bc38f01d2d3 50 /* Initialize BLE baselayer */
Rohit Grover 11:6774f4827024 51 ble.init();
mbedAustin 50:7bc38f01d2d3 52
mbedAustin 50:7bc38f01d2d3 53 /* Set up iBeacon data*/
mbedAustin 50:7bc38f01d2d3 54 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
mbedAustin 50:7bc38f01d2d3 55 ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, iBeaconPayload, sizeof(iBeaconPayload));
mbedAustin 50:7bc38f01d2d3 56
mbedAustin 50:7bc38f01d2d3 57 /* Set advertising interval. Longer interval = longer battery life */
Rohit Grover 20:5e84b5b253a5 58 ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
mbedAustin 50:7bc38f01d2d3 59 ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
Rohit Grover 19:869d8c7306b4 60 ble.startAdvertising();
ktownsend 0:7613d21e5974 61
Rohit Grover 21:a61af863b273 62 for (;;) {
mbedAustin 50:7bc38f01d2d3 63 ble.waitForEvent();
ktownsend 0:7613d21e5974 64 }
Rohit Grover 10:391c1acf4b9d 65 }