I send data (short string) in BLE Advertising with an iPhone and I want to read this string from a Windows device.
So I'm trying the sample project "BluetoothAdvertisement" from : https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BluetoothAdvertisement
I see that i receive packages, I can read the localname etc... in the callBack:
private async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{ }
But how can I read the string ?
I don't know which ways you used to add data to an Advertisement, if you are using a company-specific advertisement. I think you can get custom data section from BluetoothLEAdvertisementReceivedEventArgs
,and then query eventArgs.Advertisement.ManufacturerData
to get BluetoothLEManufacturerData
.
private async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
var DataList = eventArgs.Advertisement.ManufacturerData;
foreach (var temp in DataList)
{
var data = new byte[temp.Data.Length];
using (var reader = DataReader.FromBuffer(temp.Data))
{
reader.ReadBytes(data);
}
var str = Encoding.ASCII.GetString(data);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.