Skip to content

Commit

Permalink
- rework iBeacon API + example to more like UriBeacon
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepmistry committed May 23, 2015
1 parent 8736dfe commit c58c7d1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
16 changes: 7 additions & 9 deletions examples/ibeacon/ibeacon.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
#error "This example only works with nRF51 boards"
#endif

static BLEPeripheral blePeripheral(0, 0, 0);
iBeacon beacon;

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);
char* uuid = "a196c876-de8c-4c47-ab5a-d7afd5ae7127";
unsigned short major = 0;
unsigned short minor = 0;
unsigned short measuredPower = -55;

blePeripheral.begin();
beacon.begin(uuid, major, minor, measuredPower);
}

void loop() {
blePeripheral.poll();
beacon.loop();
}
20 changes: 16 additions & 4 deletions iBeacon.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#if defined(NRF51) || defined(__RFduino__)

#include <BLEUuid.h>
#include "BLEUuid.h"

#include "iBeacon.h"

void iBeacon::setData(BLEPeripheral& peripheral, const char* uuidString, uint16_t major, uint16_t minor, int8_t measuredPower) {
iBeacon::iBeacon() :
_blePeripheral(0, 0, 0)
{
this->_blePeripheral.setConnectable(false);
}

void iBeacon::begin(const char* uuidString, unsigned short major, unsigned short minor, char 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;
Expand All @@ -27,7 +33,13 @@ void iBeacon::setData(BLEPeripheral& peripheral, const char* uuidString, uint16_
manufacturerData[i++] = minor;
manufacturerData[i++] = measuredPower;

peripheral.setManufacturerData(manufacturerData, i);
this->_blePeripheral.setManufacturerData(manufacturerData, i);

this->_blePeripheral.begin();
}

void iBeacon::loop() {
this->_blePeripheral.poll();
}

#endif
8 changes: 7 additions & 1 deletion iBeacon.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
class iBeacon
{
public:
static void setData(BLEPeripheral& peripheral, const char* uuidString, uint16_t major, uint16_t minor, int8_t measuredPower);
iBeacon();

void begin(const char* uuidString, unsigned short major, unsigned short minor, char measuredPower);
void loop();

private:
BLEPeripheral _blePeripheral;
};

#endif
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ BLEKeyboard KEYWORD1
BLEMultimedia KEYWORD1
BLESystemControl KEYWORD1
URIBeacon KEYWORD1
iBeacon KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
Expand Down

0 comments on commit c58c7d1

Please sign in to comment.