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:
Tue Feb 03 18:23:07 2015 +0000
Revision:
0:f519dff5c6a7
Child:
1:cc428f427838
Initial commit for AltBeacon compatible program

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 0:f519dff5c6a7 16 #ifndef __BLE_IBEACON_SERVICE_H__
mbedAustin 0:f519dff5c6a7 17 #define __BLE_IBEACON_SERVICE_H__
mbedAustin 0:f519dff5c6a7 18
mbedAustin 0:f519dff5c6a7 19 #include "BLEDevice.h"
mbedAustin 0:f519dff5c6a7 20
mbedAustin 0:f519dff5c6a7 21 /**
mbedAustin 0:f519dff5c6a7 22 * @class iBeaconService
mbedAustin 0:f519dff5c6a7 23 * @brief iBeacon Service. This service sets up a device to broadcast advertising packets to mimic an iBeacon<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 0:f519dff5c6a7 29 AltBeaconService(BLEDevice &_ble, uint16_t mfgID, uint8_t beaconID[20], int8_t refRSSI, uint8_t mfgReserved = 0x00):
mbedAustin 0:f519dff5c6a7 30 ble(_ble)
mbedAustin 0:f519dff5c6a7 31 {
mbedAustin 0:f519dff5c6a7 32 data.mfgID = ((mfgID<<8) | (mfgID >>8));
mbedAustin 0:f519dff5c6a7 33 if(refRSSI > 0){refRSSI = 0;} // refRSSI can only be 0 to -127, smash everything above 0 to zero
mbedAustin 0:f519dff5c6a7 34 data.refRSSI = refRSSI;
mbedAustin 0:f519dff5c6a7 35 data.beaconCode = 0xACBE;
mbedAustin 0:f519dff5c6a7 36 data.mfgReserved = mfgReserved;
mbedAustin 0:f519dff5c6a7 37
mbedAustin 0:f519dff5c6a7 38 // copy across beacon ID
mbedAustin 0:f519dff5c6a7 39 for(int x=0; x<sizeof(data.beaconID); x++) {
mbedAustin 0:f519dff5c6a7 40 data.beaconID[x] = beaconID[x];
mbedAustin 0:f519dff5c6a7 41 }
mbedAustin 0:f519dff5c6a7 42
mbedAustin 0:f519dff5c6a7 43 // Set up alt beacon
mbedAustin 0:f519dff5c6a7 44 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE );
mbedAustin 0:f519dff5c6a7 45 // Generate the 0x1BFF part of the Alt Prefix
mbedAustin 0:f519dff5c6a7 46 ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, data.raw, sizeof(data.raw));
mbedAustin 0:f519dff5c6a7 47
mbedAustin 0:f519dff5c6a7 48 // Set advertising type
mbedAustin 0:f519dff5c6a7 49 ble.setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
mbedAustin 0:f519dff5c6a7 50 }
mbedAustin 0:f519dff5c6a7 51
mbedAustin 0:f519dff5c6a7 52 public:
mbedAustin 0:f519dff5c6a7 53 union {
mbedAustin 0:f519dff5c6a7 54 uint8_t raw[26]; // AltBeacon advertisment data
mbedAustin 0:f519dff5c6a7 55 struct {
mbedAustin 0:f519dff5c6a7 56 uint16_t mfgID; // little endian representation of manufacturer ID
mbedAustin 0:f519dff5c6a7 57 uint16_t beaconCode; // Big Endian representation of 0xBEAC
mbedAustin 0:f519dff5c6a7 58 uint8_t beaconID[20]; // 20byte beacon ID, usually 16byte UUID w/ remainder used as necessary
mbedAustin 0:f519dff5c6a7 59 int8_t refRSSI; // 1 byte signed data, 0 to -127
mbedAustin 0:f519dff5c6a7 60 uint8_t mfgReserved; // reserved for use by manufacturer to implement special features
mbedAustin 0:f519dff5c6a7 61 };
mbedAustin 0:f519dff5c6a7 62 } data;
mbedAustin 0:f519dff5c6a7 63
mbedAustin 0:f519dff5c6a7 64 private:
mbedAustin 0:f519dff5c6a7 65 BLEDevice &ble;
mbedAustin 0:f519dff5c6a7 66
mbedAustin 0:f519dff5c6a7 67 };
mbedAustin 0:f519dff5c6a7 68
mbedAustin 0:f519dff5c6a7 69 #endif //__BLE_IBEACON_SERVICE_H__