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:
1:cc428f427838
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-2015 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 1:cc428f427838 16 #ifndef __BLE_ALTBEACON_SERVICE_H__
mbedAustin 1:cc428f427838 17 #define __BLE_ALTBEACON_SERVICE_H__
mbedAustin 0:f519dff5c6a7 18
andresag 2:6ec277483638 19 #include "ble/BLE.h"
mbedAustin 0:f519dff5c6a7 20
mbedAustin 0:f519dff5c6a7 21 /**
mbedAustin 1:cc428f427838 22 * @class AltBeaconService
mbedAustin 1:cc428f427838 23 * @brief AltBeacon Service. This service sets up a device to broadcast advertising packets to mimic an AltBeacon<br>
mbedAustin 0:f519dff5c6a7 24 */
mbedAustin 0:f519dff5c6a7 25
mbedAustin 0:f519dff5c6a7 26 class AltBeaconService
mbedAustin 0:f519dff5c6a7 27 {
mbedAustin 0:f519dff5c6a7 28 public:
mbedAustin 1:cc428f427838 29 /**
andresag 2:6ec277483638 30 * @param[in] _ble
andresag 2:6ec277483638 31 * BLE object for the underlying controller.
mbedAustin 1:cc428f427838 32 * @param[in] mfgID
mbedAustin 1:cc428f427838 33 * The beacon device manufacturer's company identifier code.
mbedAustin 1:cc428f427838 34 * Usually this will coorespond to the companies BLE SIG assigned number.
mbedAustin 1:cc428f427838 35 * @param[in] beaconID
mbedAustin 1:cc428f427838 36 * A 20-byte value uniquely identifying the beacon.
mbedAustin 1:cc428f427838 37 * The big endian representation of the beacon identifier.
mbedAustin 1:cc428f427838 38 * For interoperability purposes, the first 16+ bytes of the beacon
mbedAustin 1:cc428f427838 39 * identifier should be unique to the advertiser's organizational unit.
mbedAustin 1:cc428f427838 40 * Any remaining bytes of the beacon identifier may be subdivided as needed for the use case.
mbedAustin 1:cc428f427838 41 * @param[in] refRSSI
mbedAustin 1:cc428f427838 42 * The RSSI of the beacon (as signed value from 0 to -127) as measured 1 meter from the device. Used for micro-location.
mbedAustin 1:cc428f427838 43 * @param[in] mfgReserved
mbedAustin 1:cc428f427838 44 * Used for special manufacturer data. Defaults to 0x00 if not specified.
mbedAustin 1:cc428f427838 45 */
andresag 2:6ec277483638 46 AltBeaconService(BLE &_ble, uint16_t mfgID, uint8_t beaconID[20], int8_t refRSSI, uint8_t mfgReserved = 0x00):
mbedAustin 0:f519dff5c6a7 47 ble(_ble)
mbedAustin 0:f519dff5c6a7 48 {
andresag 2:6ec277483638 49 /* refRSSI can only be 0 to -127, smash everything above 0 to zero */
andresag 2:6ec277483638 50 if (refRSSI > 0) {
andresag 2:6ec277483638 51 refRSSI = 0;
andresag 2:6ec277483638 52 }
andresag 2:6ec277483638 53 data.mfgID = ((mfgID<<8) | (mfgID >>8));
andresag 2:6ec277483638 54 data.refRSSI = refRSSI;
andresag 2:6ec277483638 55 data.beaconCode = 0xACBE;
mbedAustin 0:f519dff5c6a7 56 data.mfgReserved = mfgReserved;
mbedAustin 0:f519dff5c6a7 57
andresag 2:6ec277483638 58 /* copy across beacon ID */
andresag 2:6ec277483638 59 for(int x = 0; x < sizeof(data.beaconID); x++) {
mbedAustin 0:f519dff5c6a7 60 data.beaconID[x] = beaconID[x];
mbedAustin 0:f519dff5c6a7 61 }
mbedAustin 0:f519dff5c6a7 62
andresag 2:6ec277483638 63 /* Set up alt beacon */
andresag 2:6ec277483638 64 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
andresag 2:6ec277483638 65 /* Generate the 0x1BFF part of the Alt Prefix */
andresag 2:6ec277483638 66 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw));
mbedAustin 0:f519dff5c6a7 67
andresag 2:6ec277483638 68 /* Set advertising type */
andresag 2:6ec277483638 69 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
mbedAustin 0:f519dff5c6a7 70 }
mbedAustin 0:f519dff5c6a7 71
mbedAustin 0:f519dff5c6a7 72 public:
mbedAustin 0:f519dff5c6a7 73 union {
mbedAustin 0:f519dff5c6a7 74 uint8_t raw[26]; // AltBeacon advertisment data
mbedAustin 0:f519dff5c6a7 75 struct {
mbedAustin 0:f519dff5c6a7 76 uint16_t mfgID; // little endian representation of manufacturer ID
mbedAustin 0:f519dff5c6a7 77 uint16_t beaconCode; // Big Endian representation of 0xBEAC
mbedAustin 0:f519dff5c6a7 78 uint8_t beaconID[20]; // 20byte beacon ID, usually 16byte UUID w/ remainder used as necessary
mbedAustin 0:f519dff5c6a7 79 int8_t refRSSI; // 1 byte signed data, 0 to -127
mbedAustin 0:f519dff5c6a7 80 uint8_t mfgReserved; // reserved for use by manufacturer to implement special features
mbedAustin 0:f519dff5c6a7 81 };
mbedAustin 0:f519dff5c6a7 82 } data;
mbedAustin 0:f519dff5c6a7 83
mbedAustin 0:f519dff5c6a7 84 private:
andresag 2:6ec277483638 85 BLE &ble;
mbedAustin 0:f519dff5c6a7 86
mbedAustin 0:f519dff5c6a7 87 };
mbedAustin 0:f519dff5c6a7 88
andresag 2:6ec277483638 89 #endif /* __BLE_ALTBEACON_SERVICE_H__ */