-
-
Notifications
You must be signed in to change notification settings - Fork 188
Add iBeacon example #971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add iBeacon example #971
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* iBeacon example | ||
* | ||
* This example demonstrates how to publish an Apple-compatible iBeacon | ||
* | ||
* Created: on May 26 2025 | ||
* Author: lazd | ||
*/ | ||
|
||
#include <Arduino.h> | ||
#include <NimBLEDevice.h> | ||
#include <NimBLEBeacon.h> | ||
|
||
// According to Apple, it's important to have a 100ms advertising time | ||
#define BEACON_ADVERTISING_TIME 160 // 100ms | ||
|
||
// Hey, you! Replace this with your own unique UUID with something like https://www.uuidgenerator.net/ | ||
const char* iBeaconUUID = "26D0814C-F81C-4B2D-AC57-032E2AFF8642"; | ||
|
||
void setup() { | ||
NimBLEDevice::init("NimBLEiBeacon"); | ||
|
||
// Create beacon object | ||
NimBLEBeacon beacon; | ||
beacon.setManufacturerId(0x4C00); // fake Apple 0x004C LSB (ENDIAN_CHANGE_U16!) | ||
beacon.setMajor(1); | ||
beacon.setMinor(1); | ||
beacon.setSignalPower(0xC5); // Not required | ||
beacon.setProximityUUID(BLEUUID(iBeaconUUID)); // Unlike Bluedroid, you do not need to reverse endianness here | ||
lazd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Extract beacon data | ||
NimBLEBeacon::BeaconData beaconData = beacon.getData(); | ||
|
||
// Create advertisement data | ||
NimBLEAdvertisementData beaconAdvertisementData; | ||
beaconAdvertisementData.setFlags(0x04); // BR_EDR_NOT_SUPPORTED | ||
h2zero marked this conversation as resolved.
Show resolved
Hide resolved
|
||
beaconAdvertisementData.setManufacturerData(reinterpret_cast<const uint8_t*>(&beaconData), sizeof(NimBLEBeacon::BeaconData)); | ||
|
||
|
||
// Start advertising | ||
NimBLEAdvertising *advertising = NimBLEDevice::getAdvertising(); | ||
advertising->setAdvertisingInterval(BEACON_ADVERTISING_TIME); | ||
advertising->setAdvertisementData(beaconAdvertisementData); | ||
advertising->start(); | ||
} | ||
|
||
void loop() {} |
Uh oh!
There was an error while loading. Please reload this page.