60 lines
1.8 KiB
Arduino
Raw Normal View History

2015-04-28 22:15:43 +02:00
#include <BTstack.h>
#include <SPI.h>
2015-06-03 19:36:37 +02:00
/* EXAMPLE_START(iBeaconScanner): iBeacon Scanner
*
* @section Setup
*
* @text After BTstack.setup(), BTstack is configured to call
* advertisementCallback whenever an Advertisement was received.
* Then, a device discovery is started
*/
/* LISTING_START(iBeaconSetup): iBeacon Scanner Setup */
void setup(void){
Serial.begin(9600);
BTstack.setup();
2015-06-03 19:36:37 +02:00
BTstack.setBLEAdvertisementCallback(advertisementCallback);
BTstack.bleStartScanning();
2015-04-28 22:15:43 +02:00
}
2015-06-03 19:36:37 +02:00
/* LISTING_END(iBeaconSetup): iBeacon Scanner Setup */
2015-04-28 22:15:43 +02:00
void loop(void){
BTstack.loop();
2015-04-28 22:15:43 +02:00
}
2015-06-03 19:36:37 +02:00
/*
* @section Advertisment Callback
*
* @text Whenever an Advertisement is received, isIBeacon() checks if
* it contains an iBeacon. If yes, the Major ID, Minor ID, and UUID
* is printed.
* If it's not an iBeacon, only the BD_ADDR and the received signal strength
* (RSSI) is shown.
*/
/* LISTING_START(iBeaconCallback): iBeacon Scanner Callback */
2015-04-28 22:15:43 +02:00
void advertisementCallback(BLEAdvertisement *adv) {
if (adv->isIBeacon()) {
Serial.print("iBeacon found ");
Serial.print(adv->getBdAddr()->getAddressString());
Serial.print(", RSSI ");
Serial.print(adv->getRssi());
Serial.print(", UUID ");
Serial.print(adv->getIBeaconUUID()->getUuidString());
Serial.print(", MajorID ");
Serial.print(adv->getIBeaconMajorID());
Serial.print(", MinorID ");
Serial.print(adv->getIBecaonMinorID());
Serial.print(", Measured Power ");
Serial.println(adv->getiBeaconMeasuredPower());
} else {
Serial.print("Device discovered: ");
Serial.print(adv->getBdAddr()->getAddressString());
Serial.print(", RSSI ");
Serial.println(adv->getRssi());
}
2015-04-28 22:15:43 +02:00
}
2015-06-03 19:36:37 +02:00
/* LISTING_END(iBeaconCallback): iBeacon Scanner Callback */
2015-04-28 22:15:43 +02:00