hello

Dependencies:   BLE_API mbed nRF51822

Committer:
toanpt3
Date:
Tue Aug 23 02:48:17 2016 +0000
Revision:
0:f8875a258275
toan test 1

Who changed what in which revision?

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