Hi, I have a NANO 33 BLE board. I can write sketches and upload just fine.
I have been trying to get the major and minor values for a Beacon. The scan routine returns the MAC address.
I've gone hunting throught the src files but without luck.
Can anyone advise on getting the major and minor numbers from a beacon please?
Failing that does anyone know how to get the raw advertizing packet (which contains these numbers).
Thanks - and hoping - Richard
nuhash
January 22, 2020, 9:06am
#2
You need to get the actual advertising packet (see: iBeacon advertising packet structure – Support Center )
The version numbers are offset into the advertising packet, you should be able to modify the library to expose this data. You want to look for the code that extracts the MAC address from the BT packet, that is where you can add extra code to get the major/minor version number.
Hi, thanks for the reply.
That is exactly what I wanted to avoid if possible - hoping the full advertising packet is exposed.
Failing that, your answer looks to be my only option.
Would anyone know which module and approximately where the unpacking of the MAC from the advertising packet would be please?
Cheers - Richard
nuhash
January 23, 2020, 12:23pm
#4
Probably this:
}
}
void GAPClass::setAdvertisedServiceData(uint16_t uuid, const uint8_t data[], int length)
{
_serviceDataUuid = uuid;
_serviceData = data;
_serviceDataLength = length;
}
void GAPClass::handleLeAdvertisingReport(uint8_t type, uint8_t addressType, uint8_t address[6],
uint8_t eirLength, uint8_t eirData[], int8_t rssi)
{
if (!_scanning) {
return;
}
if (_discoverEventHandler && type == 0x03) {
// call event handler and skip adding to discover list
BLEDevice device(addressType, address);
Found it by looking for the code which issued events when a device was observed:
/*
Scan Callback
This example scans for BLE peripherals and prints out their advertising details:
address, local name, adverised service UUIDs. Unlike the Scan example, it uses
the callback style APIs and disables filtering so the peripheral discovery is
reported for every single advertisement it makes.
The circuit:
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
This example code is in the public domain.
*/
#include <ArduinoBLE.h>
void setup() {
Serial.begin(9600);
while (!Serial);
This file has been truncated. show original
You might just be able to add a public member function to BLEDevice which extracts the version numbers as the advertisement data is stored in the BLEDevice class:
}
return BLECharacteristic();
}
bool BLEDevice::hasAddress(uint8_t addressType, uint8_t address[6])
{
return (_addressType == addressType) && (memcmp(_address, address, sizeof(_address)) == 0);
}
void BLEDevice::setAdvertisementData(uint8_t type, uint8_t eirDataLength, uint8_t eirData[], int8_t rssi)
{
_advertisementTypeMask = (1 << type);
_eirDataLength = eirDataLength;
memcpy(_eirData, eirData, eirDataLength);
_rssi = rssi;
}
void BLEDevice::setScanResponseData(uint8_t eirDataLength, uint8_t eirData[], int8_t rssi)
{
_advertisementTypeMask |= (1 << 0x04);