-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Hi there,
tl; dr: I want to offer making a contribution to the gem, in case you are interested and still maintaining it.
thanks for this gem, I am going to use it to scan custom BTLE advertisements I am sending out from an ESP32.
Since my custom advertisements were not yet supported, I first looked into BlueZScanner, to see how advertisements get parsed. While I could immediately see my advertisements using BlueZScanner.each_advertisement, the data looked off:
- I could see the last few Bytes of my device identifier
- after that came my custom payload (manufacturer data)
I noticed that the scanner is depending on fixed offsets in the ad_data, which seems to collide with my beacon announcing its device name.
I scribbled together some parsing code, which will (hopefully) correctly unpack the ad_data into separate AD elements:
def scan_with_elements(device_id)
ScanBeacon::BlueZ.scan(device_id) do |mac, data, rssi|
yield nil unless data
elements = []
while data.size > 0
length, type = data.unpack('CC')
elements << {
type: type,
data: data[2..length]
}
data = data[(length + 1)..-1]
end
yield mac, elements, rssi
end
endwhich gives me correct output for my beacon:
[{:type=>9, :data=>"NN Sensor"}, {:type=>255, :data=>"\xFF\xFF\x03\xD7\x00\x8A\x02"}]
Now to my question: Would you be interested in integrating that into your gem? In that case I would try to prepare a pull request that makes this parsing available. However, in case you are not interested, I'd just have a "local" method for my own project.
Disclaimer: I have my Bluetooth LE knowledge from blog articles and I am probably still not knowing all the relevant details...