BLE iBeacon Service Exercise Solution Mobile and Ubiquitous Computing Module Birkbeck College
Dependencies: BLE_API mbed nRF51822
main.cpp@0:19a7b948aeff, 2015-03-08 (annotated)
- Committer:
- gkroussos
- Date:
- Sun Mar 08 19:44:18 2015 +0000
- Revision:
- 0:19a7b948aeff
BLE iBeacon Service ; Mobile and Ubiquitous Computing Module; Birkbeck College
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gkroussos | 0:19a7b948aeff | 1 | /* mbed Microcontroller Library |
gkroussos | 0:19a7b948aeff | 2 | * Copyright (c) 2006-2013 ARM Limited |
gkroussos | 0:19a7b948aeff | 3 | * |
gkroussos | 0:19a7b948aeff | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
gkroussos | 0:19a7b948aeff | 5 | * you may not use this file except in compliance with the License. |
gkroussos | 0:19a7b948aeff | 6 | * You may obtain a copy of the License at |
gkroussos | 0:19a7b948aeff | 7 | * |
gkroussos | 0:19a7b948aeff | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
gkroussos | 0:19a7b948aeff | 9 | * |
gkroussos | 0:19a7b948aeff | 10 | * Unless required by applicable law or agreed to in writing, software |
gkroussos | 0:19a7b948aeff | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
gkroussos | 0:19a7b948aeff | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
gkroussos | 0:19a7b948aeff | 13 | * See the License for the specific language governing permissions and |
gkroussos | 0:19a7b948aeff | 14 | * limitations under the License. |
gkroussos | 0:19a7b948aeff | 15 | */ |
gkroussos | 0:19a7b948aeff | 16 | |
gkroussos | 0:19a7b948aeff | 17 | #include "mbed.h" |
gkroussos | 0:19a7b948aeff | 18 | #include "iBeaconService.h" |
gkroussos | 0:19a7b948aeff | 19 | |
gkroussos | 0:19a7b948aeff | 20 | /** |
gkroussos | 0:19a7b948aeff | 21 | * For this demo application, populate the beacon advertisement payload |
gkroussos | 0:19a7b948aeff | 22 | * with 2 AD structures: FLAG and MSD (manufacturer specific data). |
gkroussos | 0:19a7b948aeff | 23 | * |
gkroussos | 0:19a7b948aeff | 24 | * Reference: |
gkroussos | 0:19a7b948aeff | 25 | * Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18 |
gkroussos | 0:19a7b948aeff | 26 | */ |
gkroussos | 0:19a7b948aeff | 27 | |
gkroussos | 0:19a7b948aeff | 28 | BLEDevice ble; |
gkroussos | 0:19a7b948aeff | 29 | |
gkroussos | 0:19a7b948aeff | 30 | /** |
gkroussos | 0:19a7b948aeff | 31 | * The Beacon payload has the following composition: |
gkroussos | 0:19a7b948aeff | 32 | * 128-Bit / 16byte UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 |
gkroussos | 0:19a7b948aeff | 33 | * Major/Minor = 0x1122 / 0x3344 |
gkroussos | 0:19a7b948aeff | 34 | * Tx Power = 0xC8 = 200, 2's compliment is 256-200 = (-56dB) |
gkroussos | 0:19a7b948aeff | 35 | * |
gkroussos | 0:19a7b948aeff | 36 | * Note: please remember to calibrate your beacons |
gkroussos | 0:19a7b948aeff | 37 | * TX Power for more accurate results. |
gkroussos | 0:19a7b948aeff | 38 | */ |
gkroussos | 0:19a7b948aeff | 39 | const uint8_t uuid[] = {0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, |
gkroussos | 0:19a7b948aeff | 40 | 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61 |
gkroussos | 0:19a7b948aeff | 41 | }; |
gkroussos | 0:19a7b948aeff | 42 | uint16_t majorNumber = 1122; |
gkroussos | 0:19a7b948aeff | 43 | uint16_t minorNumber = 3344; |
gkroussos | 0:19a7b948aeff | 44 | uint16_t txPower = 0xC8; |
gkroussos | 0:19a7b948aeff | 45 | |
gkroussos | 0:19a7b948aeff | 46 | int main(void) |
gkroussos | 0:19a7b948aeff | 47 | { |
gkroussos | 0:19a7b948aeff | 48 | ble.init(); |
gkroussos | 0:19a7b948aeff | 49 | |
gkroussos | 0:19a7b948aeff | 50 | iBeaconService ibeacon(ble, uuid, majorNumber, minorNumber, txPower); |
gkroussos | 0:19a7b948aeff | 51 | |
gkroussos | 0:19a7b948aeff | 52 | ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000)); /* 1000ms. */ |
gkroussos | 0:19a7b948aeff | 53 | ble.startAdvertising(); |
gkroussos | 0:19a7b948aeff | 54 | |
gkroussos | 0:19a7b948aeff | 55 | while(1) { |
gkroussos | 0:19a7b948aeff | 56 | ble.waitForEvent(); // allows or low power operation |
gkroussos | 0:19a7b948aeff | 57 | } |
gkroussos | 0:19a7b948aeff | 58 | } |