iBeacon example code for Delta module

To test with this example, please download nRF Beacon app (available both iOS and Android). In the nRF Beacon app, add beacon by pressing the "+" and then select " Add Another Beacon". You need to select the UUID as 0x0112233445566778899aabbccddeeff0, major value 0x1122 and minor value 0x3344. These are the default [UUID, major value, minor value] settings in this example.

Committer:
tsungta
Date:
Thu Mar 16 03:30:28 2017 +0000
Revision:
1:1ded0f22e084
Parent:
0:9a65d0b6f172
Update to support NQ62x and NNN50

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tsungta 0:9a65d0b6f172 1 /* mbed Microcontroller Library
tsungta 0:9a65d0b6f172 2 * Copyright (c) 2006-2015 ARM Limited
tsungta 0:9a65d0b6f172 3 *
tsungta 0:9a65d0b6f172 4 * Licensed under the Apache License, Version 2.0 (the "License");
tsungta 0:9a65d0b6f172 5 * you may not use this file except in compliance with the License.
tsungta 0:9a65d0b6f172 6 * You may obtain a copy of the License at
tsungta 0:9a65d0b6f172 7 *
tsungta 0:9a65d0b6f172 8 * http://www.apache.org/licenses/LICENSE-2.0
tsungta 0:9a65d0b6f172 9 *
tsungta 0:9a65d0b6f172 10 * Unless required by applicable law or agreed to in writing, software
tsungta 0:9a65d0b6f172 11 * distributed under the License is distributed on an "AS IS" BASIS,
tsungta 0:9a65d0b6f172 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tsungta 0:9a65d0b6f172 13 * See the License for the specific language governing permissions and
tsungta 0:9a65d0b6f172 14 * limitations under the License.
tsungta 0:9a65d0b6f172 15 */
tsungta 0:9a65d0b6f172 16
tsungta 0:9a65d0b6f172 17 #include "mbed.h"
tsungta 0:9a65d0b6f172 18 #include "ble/services/iBeacon.h"
tsungta 0:9a65d0b6f172 19
tsungta 0:9a65d0b6f172 20 BLE ble;
tsungta 0:9a65d0b6f172 21
tsungta 0:9a65d0b6f172 22 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
tsungta 0:9a65d0b6f172 23 {
tsungta 0:9a65d0b6f172 24 BLE &ble = params->ble;
tsungta 0:9a65d0b6f172 25 ble_error_t error = params->error;
tsungta 0:9a65d0b6f172 26
tsungta 0:9a65d0b6f172 27 if (error != BLE_ERROR_NONE) {
tsungta 0:9a65d0b6f172 28 return;
tsungta 0:9a65d0b6f172 29 }
tsungta 0:9a65d0b6f172 30
tsungta 0:9a65d0b6f172 31 /**
tsungta 0:9a65d0b6f172 32 * The Beacon payload has the following composition:
tsungta 1:1ded0f22e084 33 * 128-Bit / 16byte UUID = 01122334-4556-6778-899A-ABBCCDDEEFF0
tsungta 0:9a65d0b6f172 34 * Major/Minor = 0x1122 / 0x3344
tsungta 0:9a65d0b6f172 35 * Tx Power = 0xC8 = 200, 2's compliment is 256-200 = (-56dB)
tsungta 0:9a65d0b6f172 36 *
tsungta 0:9a65d0b6f172 37 * Note: please remember to calibrate your beacons TX Power for more accurate results.
tsungta 0:9a65d0b6f172 38 */
tsungta 1:1ded0f22e084 39 const uint8_t uuid[] = {0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67, 0x78,
tsungta 1:1ded0f22e084 40 0x89, 0x9A, 0xAB, 0xBC, 0xCD, 0xDE, 0xEF, 0xF0};
tsungta 0:9a65d0b6f172 41 uint16_t majorNumber = 1122;
tsungta 0:9a65d0b6f172 42 uint16_t minorNumber = 3344;
tsungta 0:9a65d0b6f172 43 uint16_t txPower = 0xC8;
tsungta 0:9a65d0b6f172 44 iBeacon *ibeacon = new iBeacon(ble, uuid, majorNumber, minorNumber, txPower);
tsungta 0:9a65d0b6f172 45
tsungta 0:9a65d0b6f172 46 ble.gap().setAdvertisingInterval(1000); /* 1000ms. */
tsungta 0:9a65d0b6f172 47 ble.gap().startAdvertising();
tsungta 0:9a65d0b6f172 48 }
tsungta 0:9a65d0b6f172 49
tsungta 0:9a65d0b6f172 50 int main(void)
tsungta 0:9a65d0b6f172 51 {
tsungta 0:9a65d0b6f172 52 ble.init(bleInitComplete);
tsungta 0:9a65d0b6f172 53
tsungta 0:9a65d0b6f172 54 /* SpinWait for initialization to complete. This is necessary because the
tsungta 0:9a65d0b6f172 55 * BLE object is used in the main loop below. */
tsungta 0:9a65d0b6f172 56 while (!ble.hasInitialized()) { /* spin loop */ }
tsungta 0:9a65d0b6f172 57
tsungta 0:9a65d0b6f172 58 while (true) {
tsungta 0:9a65d0b6f172 59 ble.waitForEvent(); // allows or low power operation
tsungta 0:9a65d0b6f172 60 }
tsungta 0:9a65d0b6f172 61 }