forked from sandeepmistry/arduino-BLEPeripheral
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sandeepmistry#21 from george-hawkins/master
Add new iBeacon class for nRF51 boards.
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <BLEPeripheral.h> | ||
#include <iBeacon.h> | ||
|
||
#if !defined(NRF51) && !defined(__RFduino__) | ||
#error "This example only works with nRF51 boards" | ||
#endif | ||
|
||
static BLEPeripheral blePeripheral(0, 0, 0); | ||
|
||
void setup() { | ||
char* uuid = "a196c876-de8c-4c47-ab5a-d7afd5ae7127"; | ||
uint16_t major = 0; | ||
uint16_t minor = 0; | ||
int8_t measuredPower = -55; | ||
|
||
iBeacon::setData(blePeripheral, uuid, major, minor, measuredPower); | ||
|
||
blePeripheral.begin(); | ||
} | ||
|
||
void loop() { | ||
blePeripheral.poll(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#if defined(NRF51) || defined(__RFduino__) | ||
|
||
#include <BLEUuid.h> | ||
|
||
#include "iBeacon.h" | ||
|
||
void iBeacon::setData(BLEPeripheral& peripheral, const char* uuidString, uint16_t major, uint16_t minor, int8_t measuredPower) { | ||
unsigned char manufacturerData[MAX_UUID_LENGTH + 9]; // 4 bytes of header and 5 bytes of trailer. | ||
BLEUuid uuid(uuidString); | ||
int i = 0; | ||
|
||
// 0x004c = Apple, see https://www.bluetooth.org/en-us/specification/assigned-numbers/company-identifiers | ||
manufacturerData[i++] = 0x4c; // Apple Company Identifier LE (16 bit) | ||
manufacturerData[i++] = 0x00; | ||
|
||
// See "Beacon type" in "Building Applications with IBeacon". | ||
manufacturerData[i++] = 0x02; | ||
manufacturerData[i++] = uuid.length() + 5; | ||
|
||
for (int j = (uuid.length() - 1); j >= 0; j--) { | ||
manufacturerData[i++] = uuid.data()[j]; | ||
} | ||
|
||
manufacturerData[i++] = major >> 8; | ||
manufacturerData[i++] = major; | ||
manufacturerData[i++] = minor >> 8; | ||
manufacturerData[i++] = minor; | ||
manufacturerData[i++] = measuredPower; | ||
|
||
peripheral.setManufacturerData(manufacturerData, i); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef _I_BEACON_H_ | ||
#define _I_BEACON_H_ | ||
|
||
#if defined(NRF51) || !defined(__RFduino__) | ||
|
||
#include "BLEPeripheral.h" | ||
|
||
class iBeacon | ||
{ | ||
public: | ||
static void setData(BLEPeripheral& peripheral, const char* uuidString, uint16_t major, uint16_t minor, int8_t measuredPower); | ||
}; | ||
|
||
#endif | ||
|
||
#endif |