Windows runtime 我可以通过Windows.Devices.Bluetooth.Advertision.BluetoothLEManufacturerData读取iPhone信标吗

Windows runtime 我可以通过Windows.Devices.Bluetooth.Advertision.BluetoothLEManufacturerData读取iPhone信标吗,windows-runtime,ibeacon,windows-10,Windows Runtime,Ibeacon,Windows 10,根据,我需要设置CompanyID(UInt16)和数据(IBuffer,示例中的UInt16)来开始关注广告商 在iPhone中,我可以将信标UUID设置为4B503F1B-C09C-4AEE-972F-750E9D346784。在互联网上阅读,我发现苹果公司的id是0x004C,所以我尝试了0x004C和0x4C00 这是我到目前为止的代码,但当然,它不起作用 var manufacturerData = new BluetoothLEManufacturerData(); // Then

根据,我需要设置
CompanyID
UInt16)和数据(IBuffer,示例中的UInt16)来开始关注广告商

在iPhone中,我可以将信标UUID设置为
4B503F1B-C09C-4AEE-972F-750E9D346784
。在互联网上阅读,我发现苹果公司的id是
0x004C
,所以我尝试了
0x004C
0x4C00

这是我到目前为止的代码,但当然,它不起作用

var manufacturerData = new BluetoothLEManufacturerData();

// Then, set the company ID for the manufacturer data. Here we picked an unused value: 0xFFFE
manufacturerData.CompanyId = 0x4C00;

// Finally set the data payload within the manufacturer-specific section
// Here, use a 16-bit UUID: 0x1234 -> {0x34, 0x12} (little-endian)
var writer = new DataWriter();
writer.WriteGuid(Guid.Parse("4B503F1B-C09C-4AEE-972F-750E9D346784"));

// Make sure that the buffer length can fit within an advertisement payload. Otherwise you will get an exception.
manufacturerData.Data = writer.DetachBuffer();
我还尝试反转UUID中的字节:

writer.WriteGuid(Guid.Parse("504B1B3F-9CC0-EE4A-2F97-0E75349D8467"));

到目前为止还没有成功。我混合了两种完全不同的技术吗?

在Windows 10上检测信标需要做的最重要的事情是使用新类

问题中的代码似乎集中于设置一个过滤器,以便只查找与公司代码匹配的特定蓝牙LE广告,可能还包括广告中包含的UUID。虽然这是一种方法,但严格来说并不是必需的——您可以简单地查找所有蓝牙LE广告,然后对它们进行解码以查看它们是否为信标广告

我在下面粘贴了一些代码,显示了我认为您想要做的事情主要警告:我没有亲自测试此代码,因为我没有Windows 10开发环境。如果您自己尝试并进行更正,请告诉我,我将更新我的答案

private BluetoothLEAdvertisementWatcher bluetoothLEAdvertisementWatcher;

public LookForBeacons() {
    bluetoothLEAdvertisementWatcher = new BluetoothLEAdvertisementWatcher();
    bluetoothLEAdvertisementWatcher.Received += OnAdvertisementReceived;
    bluetoothLEAdvertisementWatcher.Start();
}


private async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs) {

    var manufacturerSections = eventArgs.Advertisement.ManufacturerData;
    if (manufacturerSections.Count > 0) {
        var manufacturerData = manufacturerSections[0];
        var data = new byte[manufacturerData.Data.Length];
        using (var reader = DataReader.FromBuffer(manufacturerData.Data)) {
            reader.ReadBytes(data);

            // If we arrive here we have detected a Bluetooth LE advertisement
            // Add code here to decode the the bytes in data and read the beacon identifiers

        }
    }
}
下一个明显的问题是如何解码广告的字节?搜索web并找出各种信标类型的字节序列非常容易,即使是专有的。为了让这个答案简洁明了,不涉及知识产权,我将简单描述如何解码开源AltBeacon广告的字节:

18 01 be ac 2f 23 44 54 cf 6d 4a 0f ad f2 f4 91 1b a9 ff a6 00 01 00 02 c5 00
这被解码为:

  • 前两个字节是公司代码(0x0118=Radius网络)
  • 接下来的两个字节是信标类型代码(0xacbe=AltBeacon)
  • 接下来的16个字节是第一个标识符2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6
  • 接下来的2个字节是第二个标识符0x0001
  • 接下来的2个字节是第三个标识符0x0002
  • 以下字节为功率校准值0xC5->-59 dBm

这绝对正确。我只需注释掉watcher.advisementfilter.advision.ManufacturerData.Add,返回的样本是
type=ConnectableUndirected,rssi=-50,name=,ManufacturerData=[0x4C:02-15-0F-4E-1E-48-26-F7-4A-47-A0-6C-D9-B8-42-7D-30-3F-00-00-09]
。所以,我想,
02-15
一定是信标类型。我已经测试过了,效果很好,非常感谢,它帮了我很多忙@我知道这是很久以前的事了,但是谢谢你的详细解释!如果你碰巧再次遇到这个问题,你能扩展到“非常容易搜索web…”吗?我想看看一些设备的配置文件信标的描述,特别是包括启动InTemp logger和“Tiles”,这些是你用来查找密钥的东西:)Cheers@Dave,这就是研究的意义所在。我不知道世界上成千上万的蓝牙设备的字节序列。您必须从制造商处获取文档,或者使用谷歌或类似工具查找其他人为每种设备类型编写的文档。