Hi,
Does anyone have a sample code, once the device is found to get the manufacturing data of the BLE device?
Thanks
Johan
Hi,
Does anyone have a sample code, once the device is found to get the manufacturing data of the BLE device?
Thanks
Johan
I don't have sample code but it should be relatively straightforward.
Using the ArduinoBLE library I suggest you start with the BLE Central example "Peripheral Explorer".
This uses the BLEdevice class, which you'll need as within this class there are the following functions, which you can use to retrieve manufacturing data:
bool hasManufacturerData() const;
int manufacturerDataLength() const;
int manufacturerData(uint8_t value[], int length) const;
Then you can modify this example to do something like:
#include <ArduinoBLE.h>
void setup() {
Serial.begin(115200);
while (!Serial);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy module failed!");
while (1);
}
Serial.println("Bluetooth® Low Energy Central - Peripheral Explorer");
// start scanning for peripherals
BLE.scan();
}
void loop() {
// check if a peripheral has been discovered
BLEDevice peripheral = BLE.available();
if (peripheral) {
// discovered a peripheral, print out address, local name, and advertised service
Serial.print("Found ");
Serial.print(peripheral.address());
Serial.print(" '");
Serial.print(peripheral.localName());
Serial.print("' ");
Serial.print(peripheral.advertisedServiceUuid());
Serial.println();
// see if peripheral has manufacturing data
if (peripheral.hasManufacturerData()) {
Serial.print("Found manufacturing data, which has length ");
int ManuDataLen = peripheral.manufacturerDataLength();
Serial.println(ManuDataLen);
// retrieve the data.... using manufacturerData etc.
uint8_t manuDataBuffer[ManuDataLen];
if (peripheral.manufacturerData(manuDataBuffer, ManuDataLen)) {
Serial.print("Manufacturer Data: ");
for (int x = 0; x < ManuDataLen; x++) {
Serial.print(manuDataBuffer[x]);
}
Serial.println();
}
}
}
}
Thank you very much. I will try and let you know.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.