AltBeacon program for embedded BLE. This program demonstrates how to set up a BLE device to broadcast AltBLE compatible data. Please see the official website for more details. https://github.com/AltBeacon/spec and http://altbeacon.org/

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_AltBeacon by Austin Blackstone

Description

AltBeacon is an open beacon standard developed by Roving Networks. AltBeacons an alternative to the closed sourced and heavily licensed iBeacon standard.

For full details please see the AltBeacon repository

Committer:
andresag
Date:
Tue Jan 12 11:34:09 2016 +0000
Revision:
2:6ec277483638
Parent:
0:f519dff5c6a7
Update example to latest BLE API.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 0:f519dff5c6a7 1 /* mbed Microcontroller Library
mbedAustin 0:f519dff5c6a7 2 * Copyright (c) 2006-2013 ARM Limited
mbedAustin 0:f519dff5c6a7 3 *
mbedAustin 0:f519dff5c6a7 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbedAustin 0:f519dff5c6a7 5 * you may not use this file except in compliance with the License.
mbedAustin 0:f519dff5c6a7 6 * You may obtain a copy of the License at
mbedAustin 0:f519dff5c6a7 7 *
mbedAustin 0:f519dff5c6a7 8 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 0:f519dff5c6a7 9 *
mbedAustin 0:f519dff5c6a7 10 * Unless required by applicable law or agreed to in writing, software
mbedAustin 0:f519dff5c6a7 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbedAustin 0:f519dff5c6a7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 0:f519dff5c6a7 13 * See the License for the specific language governing permissions and
mbedAustin 0:f519dff5c6a7 14 * limitations under the License.
mbedAustin 0:f519dff5c6a7 15 */
mbedAustin 0:f519dff5c6a7 16
mbedAustin 0:f519dff5c6a7 17 #include "mbed.h"
mbedAustin 0:f519dff5c6a7 18 #include "AltBeaconService.h"
andresag 2:6ec277483638 19 #include "ble/BLE.h"
mbedAustin 0:f519dff5c6a7 20
mbedAustin 0:f519dff5c6a7 21 /**
mbedAustin 0:f519dff5c6a7 22 * For this demo application, populate the beacon advertisement payload
mbedAustin 0:f519dff5c6a7 23 * with 2 AD structures: FLAG and MSD (manufacturer specific data).
mbedAustin 0:f519dff5c6a7 24 *
mbedAustin 0:f519dff5c6a7 25 * Reference:
mbedAustin 0:f519dff5c6a7 26 * Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18
mbedAustin 0:f519dff5c6a7 27 */
mbedAustin 0:f519dff5c6a7 28
mbedAustin 0:f519dff5c6a7 29 /**
mbedAustin 0:f519dff5c6a7 30 * The AltBeacon requires a manufacturer ID, and a Beacon ID
mbedAustin 0:f519dff5c6a7 31 * the first 16 bytes of the BeaconID should be a UUID and the remaining
mbedAustin 0:f519dff5c6a7 32 * 4 bytes can be used as you see fit.
mbedAustin 0:f519dff5c6a7 33 *
mbedAustin 0:f519dff5c6a7 34 * Note: please remember to calibrate your beacon
mbedAustin 0:f519dff5c6a7 35 * RSSI for more accurate results.
mbedAustin 0:f519dff5c6a7 36 */
andresag 2:6ec277483638 37 uint8_t beaconID[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
andresag 2:6ec277483638 38 0x10,0x11,0x12,0x13,0x14,0x15,0x00,0x01,0x00,0x02};
andresag 2:6ec277483638 39 uint16_t manufacturerID = 0x5900; /* Nordic SIG ID */
andresag 2:6ec277483638 40 int8_t rssi = -122;
andresag 2:6ec277483638 41
andresag 2:6ec277483638 42 AltBeaconService *altBeaconServicePtr;
andresag 2:6ec277483638 43
andresag 2:6ec277483638 44 /**
andresag 2:6ec277483638 45 * This function is called when the ble initialization process has failed
andresag 2:6ec277483638 46 */
andresag 2:6ec277483638 47 void onBleInitError(BLE &ble, ble_error_t error)
andresag 2:6ec277483638 48 {
andresag 2:6ec277483638 49 /* Initialization error handling should go here */
andresag 2:6ec277483638 50 }
mbedAustin 0:f519dff5c6a7 51
andresag 2:6ec277483638 52 /**
andresag 2:6ec277483638 53 * Callback triggered when the ble initialization process has finished
andresag 2:6ec277483638 54 */
andresag 2:6ec277483638 55 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
andresag 2:6ec277483638 56 {
andresag 2:6ec277483638 57 BLE& ble = params->ble;
andresag 2:6ec277483638 58 ble_error_t error = params->error;
andresag 2:6ec277483638 59
andresag 2:6ec277483638 60 if (error != BLE_ERROR_NONE) {
andresag 2:6ec277483638 61 /* In case of error, forward the error handling to onBleInitError */
andresag 2:6ec277483638 62 onBleInitError(ble, error);
andresag 2:6ec277483638 63 return;
andresag 2:6ec277483638 64 }
andresag 2:6ec277483638 65
andresag 2:6ec277483638 66 /* Ensure that it is the default instance of BLE */
andresag 2:6ec277483638 67 if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
andresag 2:6ec277483638 68 return;
andresag 2:6ec277483638 69 }
andresag 2:6ec277483638 70
andresag 2:6ec277483638 71 /* Initialize AltBeacon */
andresag 2:6ec277483638 72 altBeaconServicePtr =new AltBeaconService(ble, manufacturerID, beaconID, rssi);
andresag 2:6ec277483638 73
andresag 2:6ec277483638 74 /* Set advertising time */
andresag 2:6ec277483638 75 ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
andresag 2:6ec277483638 76
andresag 2:6ec277483638 77 /* Start advertising */
andresag 2:6ec277483638 78 ble.startAdvertising();
andresag 2:6ec277483638 79 }
mbedAustin 0:f519dff5c6a7 80
mbedAustin 0:f519dff5c6a7 81 int main(void)
mbedAustin 0:f519dff5c6a7 82 {
andresag 2:6ec277483638 83 BLE& ble = BLE::Instance();
mbedAustin 0:f519dff5c6a7 84
andresag 2:6ec277483638 85 /* Initialize BLE baselayer */
andresag 2:6ec277483638 86 ble.init(bleInitComplete);
mbedAustin 0:f519dff5c6a7 87
andresag 2:6ec277483638 88 while(true) {
andresag 2:6ec277483638 89 ble.waitForEvent(); /* Allow low power operation */
mbedAustin 0:f519dff5c6a7 90 }
mbedAustin 0:f519dff5c6a7 91 }