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

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_iBeacon by Bluetooth Low Energy

Committer:
rgrover1
Date:
Fri Nov 28 14:17:32 2014 +0000
Revision:
48:2f0f293a4966
Parent:
47:447eb23e67e2
Child:
50:7bc38f01d2d3
updating to 0.2.5 of the BLE_API

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
Rohit Grover 32:7b7093b653a8 20 BLEDevice ble;
Rohit Grover 31:93e50a3c3dc6 21
Rohit Grover 10:391c1acf4b9d 22 /*
Rohit Grover 10:391c1acf4b9d 23 * For this demo application, populate the beacon advertisement payload
Rohit Grover 15:4e1b36b73213 24 * with 2 AD structures: FLAG and MSD (manufacturer specific data).
Rohit Grover 10:391c1acf4b9d 25 *
Rohit Grover 10:391c1acf4b9d 26 * Reference:
Rohit Grover 10:391c1acf4b9d 27 * Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18
Rohit Grover 10:391c1acf4b9d 28 */
ktownsend 0:7613d21e5974 29
Rohit Grover 14:dfdf0c8b1c09 30 /*
Rohit Grover 15:4e1b36b73213 31 * The Beacon payload (encapsulated within the MSD advertising data structure)
Rohit Grover 15:4e1b36b73213 32 * has the following composition:
rgrover1 44:71ff94cd9c1d 33 * 128-Bit UUID = 01 12 23 34 45 56 67 78 89 9A AB BC CD DE EF F0
Rohit Grover 10:391c1acf4b9d 34 * Major/Minor = 0000 / 0000
Rohit Grover 10:391c1acf4b9d 35 * Tx Power = C8
Rohit Grover 10:391c1acf4b9d 36 */
rgrover1 41:51f585d14675 37 const uint8_t beaconPayload[] = {
rgrover1 43:b5dc3241fc91 38 0x4C, 0x00,
rgrover1 43:b5dc3241fc91 39 0x02,
rgrover1 43:b5dc3241fc91 40 0x15,
rgrover1 44:71ff94cd9c1d 41 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78,
rgrover1 44:71ff94cd9c1d 42 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf0,
rgrover1 43:b5dc3241fc91 43 0x00, 0x00,
rgrover1 43:b5dc3241fc91 44 0x00, 0x00,
rgrover1 48:2f0f293a4966 45 0xC8
Rohit Grover 10:391c1acf4b9d 46 };
Rohit Grover 10:391c1acf4b9d 47
ktownsend 0:7613d21e5974 48 int main(void)
ktownsend 0:7613d21e5974 49 {
Rohit Grover 11:6774f4827024 50 ble.init();
ktownsend 0:7613d21e5974 51
Rohit Grover 37:205deeded79d 52 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
Rohit Grover 27:8d4f5bda1191 53 ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, beaconPayload, sizeof(beaconPayload));
ktownsend 0:7613d21e5974 54
Rohit Grover 20:5e84b5b253a5 55 ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
rgrover1 48:2f0f293a4966 56 ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000));
Rohit Grover 19:869d8c7306b4 57 ble.startAdvertising();
ktownsend 0:7613d21e5974 58
Rohit Grover 21:a61af863b273 59 for (;;) {
Rohit Grover 31:93e50a3c3dc6 60 ble.waitForEvent();
ktownsend 0:7613d21e5974 61 }
Rohit Grover 10:391c1acf4b9d 62 }