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:
mbedAustin
Date:
Fri Mar 20 21:10:12 2015 +0000
Revision:
1:cc428f427838
Parent:
0:f519dff5c6a7
Child:
2:6ec277483638
updated documentation so the API guide will compile correctly.

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
mbedAustin 0:f519dff5c6a7 19 #include "BLEDevice.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 /**
mbedAustin 1:cc428f427838 30 * @param[ref] _ble
mbedAustin 1:cc428f427838 31 * BLEDevice 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 */
mbedAustin 0:f519dff5c6a7 46 AltBeaconService(BLEDevice &_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 {
mbedAustin 0:f519dff5c6a7 49 data.mfgID = ((mfgID<<8) | (mfgID >>8));
mbedAustin 0:f519dff5c6a7 50 if(refRSSI > 0){refRSSI = 0;} // refRSSI can only be 0 to -127, smash everything above 0 to zero
mbedAustin 0:f519dff5c6a7 51 data.refRSSI = refRSSI;
mbedAustin 0:f519dff5c6a7 52 data.beaconCode = 0xACBE;
mbedAustin 0:f519dff5c6a7 53 data.mfgReserved = mfgReserved;
mbedAustin 0:f519dff5c6a7 54
mbedAustin 0:f519dff5c6a7 55 // copy across beacon ID
mbedAustin 0:f519dff5c6a7 56 for(int x=0; x<sizeof(data.beaconID); x++) {
mbedAustin 0:f519dff5c6a7 57 data.beaconID[x] = beaconID[x];
mbedAustin 0:f519dff5c6a7 58 }
mbedAustin 0:f519dff5c6a7 59
mbedAustin 0:f519dff5c6a7 60 // Set up alt beacon
mbedAustin 0:f519dff5c6a7 61 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
mbedAustin 0:f519dff5c6a7 62 // Generate the 0x1BFF part of the Alt Prefix
mbedAustin 0:f519dff5c6a7 63 ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw));
mbedAustin 0:f519dff5c6a7 64
mbedAustin 0:f519dff5c6a7 65 // Set advertising type
mbedAustin 0:f519dff5c6a7 66 ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
mbedAustin 0:f519dff5c6a7 67 }
mbedAustin 0:f519dff5c6a7 68
mbedAustin 0:f519dff5c6a7 69 public:
mbedAustin 0:f519dff5c6a7 70 union {
mbedAustin 0:f519dff5c6a7 71 uint8_t raw[26]; // AltBeacon advertisment data
mbedAustin 0:f519dff5c6a7 72 struct {
mbedAustin 0:f519dff5c6a7 73 uint16_t mfgID; // little endian representation of manufacturer ID
mbedAustin 0:f519dff5c6a7 74 uint16_t beaconCode; // Big Endian representation of 0xBEAC
mbedAustin 0:f519dff5c6a7 75 uint8_t beaconID[20]; // 20byte beacon ID, usually 16byte UUID w/ remainder used as necessary
mbedAustin 0:f519dff5c6a7 76 int8_t refRSSI; // 1 byte signed data, 0 to -127
mbedAustin 0:f519dff5c6a7 77 uint8_t mfgReserved; // reserved for use by manufacturer to implement special features
mbedAustin 0:f519dff5c6a7 78 };
mbedAustin 0:f519dff5c6a7 79 } data;
mbedAustin 0:f519dff5c6a7 80
mbedAustin 0:f519dff5c6a7 81 private:
mbedAustin 0:f519dff5c6a7 82 BLEDevice &ble;
mbedAustin 0:f519dff5c6a7 83
mbedAustin 0:f519dff5c6a7 84 };
mbedAustin 0:f519dff5c6a7 85
mbedAustin 1:cc428f427838 86 #endif //__BLE_ALTBEACON_SERVICE_H__