I have a a Victron battery monitor that acts as a Bluetooth Low Energy (BLE) peripheral named "BATTbank_SmartShunt". It advertises the usual data for BLE, including "Extra Manufacturer Data". As the data is advertised it can be read without connecting. Some of the data is also encrypted.
This is what the advertised data looks like when I use the excellent BLE sniffer app "nRF Connect".
The manufacturer data is the group of approx. 30 HEX bytes starting 0x100289A302BC ... etc.
Once I get hold of these bytes (!) I will be able parse them one by one, then decrypt to extract info like battery volts, amps etc.
I have made a sketch to receive the advertised data on my ESP32. Unfortunately I have to use the Bluetooth LE library included in ESP32 package and it returns the manufacturer data in Arduino String format. I always avoid using String ! But I have no choice, it's used throughout the lib..
My sketch is derived from the "Client" example provided with the BLE library. It's working in part, producing this output:
This is the relevant part of my sketch
#include <Streaming.h>
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
if (advertisedDevice.getName() == "BATTbank_SmartShunt") {
BLEDevice::getScan()->stop();
myDevice = new BLEAdvertisedDevice(advertisedDevice);
Serial << "Found: ("
<< advertisedDevice.getManufacturerData().length() << ") "
<< advertisedDevice.getName().c_str() << " ["
<< advertisedDevice.getManufacturerData() << "]\n";
}
} // onResult
}; // MyAdvertisedDeviceCallbacks
If I instead use this above
advertisedDevice.getManufacturerData().c_str()
the result is the same.
This snippet is an extract from BLEAdvertisedDevice.cpp in the library:
/**
* @brief Get the manufacturer data.
* @return The manufacturer data of the advertised device.
*/
String BLEAdvertisedDevice::getManufacturerData() {
return m_manufacturerData;
} // getManufacturerData
I've tried using .toCharArray() and .toInt() and even _HEX, but so far I have not extracted the HEX data I need.
Any and all coding suggestions welcomed ...
TIA