Add iBeacon example#971
Conversation
| // Create advertisement data | ||
| NimBLEAdvertisementData beaconAdvertisementData; | ||
| beaconAdvertisementData.setFlags(0x04); // BR_EDR_NOT_SUPPORTED | ||
| beaconAdvertisementData.setManufacturerData(reinterpret_cast<const uint8_t*>(&beaconData), sizeof(NimBLEBeacon::BeaconData)); |
There was a problem hiding this comment.
I'm curious if there's a better way to do this, I noticed I can't directly pass beacon.getData() as it doesn't match any of setManufacturerData's signatures.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Sounds right to me, so what would the API end up looking like? Something like this would be nice:
advertising->setAdvertisementData(beacon.getAdvertisingData());
There was a problem hiding this comment.
Sorry for the delay getting back to you. We can change this line to simply beaconAdvertisementData.setManufacturerData(beacon.getData());
In order to make that work you will need to add an operator to the beacondata class so it looks like :
struct BeaconData {
uint16_t manufacturerId{0x4c00};
uint8_t subType{0x02};
uint8_t subTypeLength{0x15};
uint8_t proximityUUID[16]{};
uint16_t major{};
uint16_t minor{};
int8_t signalPower{};
operator std::vector<uint8_t> () const {
return std::vector<uint8_t>(reinterpret_cast<const uint8_t*>(this),
reinterpret_cast<const uint8_t*>(this) + sizeof(BeaconData));
}
} __attribute__((packed));
There was a problem hiding this comment.
Implemented! Now all that is left would be to remove the need for this
beaconAdvertisementData.setFlags(0x04); // BR_EDR_NOT_SUPPORTED
How should we go about doing that? Can we simply omit the call, or do we need to call setFlags() somewhere, like in the NimBLEAdvertisementData constructor?
There was a problem hiding this comment.
I think we should leave this for now, it would overly complicate things to accommodate.
h2zero
left a comment
There was a problem hiding this comment.
Thanks, looks good, a couple of comments to work on.
| // Create advertisement data | ||
| NimBLEAdvertisementData beaconAdvertisementData; | ||
| beaconAdvertisementData.setFlags(0x04); // BR_EDR_NOT_SUPPORTED | ||
| beaconAdvertisementData.setManufacturerData(reinterpret_cast<const uint8_t*>(&beaconData), sizeof(NimBLEBeacon::BeaconData)); |
There was a problem hiding this comment.
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.
…vertisementData.setManufacturerData()
| // Create advertisement data | ||
| NimBLEAdvertisementData beaconAdvertisementData; | ||
| beaconAdvertisementData.setFlags(0x04); // BR_EDR_NOT_SUPPORTED | ||
| beaconAdvertisementData.setManufacturerData(reinterpret_cast<const uint8_t*>(&beaconData), sizeof(NimBLEBeacon::BeaconData)); |
There was a problem hiding this comment.
I think we should leave this for now, it would overly complicate things to accommodate.
|
Thanks! |
|
Thanks for the guidance on landing this pR, glad I could contribute something back! |
This example advertises an iBeacon that is recognized by Apple's CLLocationManager. I've tested this approach with a Swift app I'm building and it works great.
Based loosely on a previous Bluedroid implementation here, modified for NimBLE.
This is the example closes #911
cc @jdbravo