-
-
Notifications
You must be signed in to change notification settings - Fork 213
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.
|
||
|
|
||
| // 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.
|
||
| beaconAdvertisementData.setManufacturerData(reinterpret_cast<const uint8_t*>(&beaconData), sizeof(NimBLEBeacon::BeaconData)); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious if there's a better way to do this, I noticed I can't directly pass
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I see here is that this isn't needed. Instead what should be done is the beacon class should be fixed to include the flags since that is all that is happening here. They do not change in this repo as BT classic is not supported. Instead lets add this as a fixed data to the beacon data in the beacon class.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds right to me, so what would the API end up looking like? Something like this would be nice:
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the delay getting back to you. We can change this line to simply In order to make that work you will need to add an operator to the beacondata class so it looks like :
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented! Now all that is left would be to remove the need for this How should we go about doing that? Can we simply omit the call, or do we need to call
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should leave this for now, it would overly complicate things to accommodate. |
||
|
|
||
| // 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.