MS提供了样本来发送和接收蓝牙低能广告。我看到这个非常有用的答案破坏了iBeacon包。还有一个例子将BluetoothLEAdvertisement.ManufacturerData设置为ibeacon标准。
我可以问如何设置BluetoothLEAdvertisement的旗帜吗?例如,将值设置为: 02-01-06。
谢谢
编辑1:这是代码:
using System;
using System.Management;
using System.Text.RegularExpressions;
using Windows.Devices.Bluetooth.Advertisement;
using System.Runtime.InteropServices.WindowsRuntime;
namespace BLE_iBeacon
{
class IBeacon
{
static void Main()
{
Console.WriteLine("Advertising as iBeacon. Press Enter to exit");
// Create and initialize a new publisher instance.
BluetoothLEAdvertisementPublisher publisher = new BluetoothLEAdvertisementPublisher();
// Add a manufacturer-specific section:
var manufacturerData = new BluetoothLEManufacturerData();
// Set the company ID for the manufacturer data.
// 0x004C Apple, Inc.
manufacturerData.CompanyId = 0x004C;
byte[] dataArray = new byte[] {
// last 2 bytes of Apple's iBeacon
0x02, 0x15,
// UUID E4 C8 A4 FC F6 8B 47 0D 95 9F 29 38 2A F7 2C E7
0xE4, 0xC8, 0xA4, 0xFC,
0xF6, 0x8B, 0x47, 0x0D,
0x95, 0x9F, 0x29, 0x38,
0x2A, 0xF7, 0x2C, 0xE7,
// Major
0x00, 0x00,
// Minor
0x00, 0x01,
// TX power
0xC5
};
manufacturerData.Data = dataArray.AsBuffer();
// Add the manufacturer data to the advertisement publisher:
publisher.Advertisement.ManufacturerData.Add(manufacturerData);
publisher.Advertisement.Flags = BluetoothLEAdvertisementFlags.GeneralDiscoverableMode;
publisher.Start();
Console.Read();
publisher.Stop();
}
}
}
编辑2:
在C#代码中,如果我不设置标志,我的windows膝上型计算机将为原始数据包做广告,如下所示:
04 3E 27 02 01
02 01 0D 45 84 D3 68 21 1B 1A FF 4C 00
02 15 E4 C8 A4 FC F6 8B 47 0D 95 9F 29 38 2A F7 2C E7
00 00 00 01 C5 BA
我的目的是使用覆盆子作为BLE接收器。我使用了Radius的代码这里。您可以在ibeacon_scan
脚本中看到,它们通过以下方式检查广告的数据包,以确定它是否为iBeacon:
if [[ $packet =~ ^04\ 3E\ 2A\ 02\ 01\ .{26}\ 02\ 01\ .{14}\ 02\ 15 ]]; then
因此,之前的原始数据包将不会被识别,因为缺少标志部分。我想知道我是否可以用旗子做广告,比如:
04 3E 2A 02 01
02 01 0D 45 84 D3 68 21 1B **02 01 1A** 1A FF 4C 00
02 15 E4 C8 A4 FC F6 8B 47 0D 95 9F 29 38 2A F7 2C E7
00 00 00 01 C5 BA
而不是改变pi中的扫描脚本。
发布于 2016-06-13 19:28:21
iBeacon on Windows
以下代码在Windows 10计算机上发布iBeacon:
// Create and initialize a new publisher instance.
BluetoothLEAdvertisementPublisher publisher = new BluetoothLEAdvertisementPublisher();
// Add a manufacturer-specific section:
var manufacturerData = new BluetoothLEManufacturerData();
// Set the company ID for the manufacturer data.
// 0x004C Apple, Inc.
manufacturerData.CompanyId = 0x004c;
// Create the payload
var writer = new DataWriter();
byte[] dataArray = new byte[] {
// last 2 bytes of Apple's iBeacon
0x02, 0x15,
// UUID e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0
0xe2, 0xc5, 0x6d, 0xb5,
0xdf, 0xfb, 0x48, 0xd2,
0xb0, 0x60, 0xd0, 0xf5,
0xa7, 0x10, 0x96, 0xe0,
// Major
0x00, 0x00,
// Minor
0x00, 0x01,
// TX power
0xc5
};
writer.WriteBytes(dataArray);
manufacturerData.Data = writer.DetachBuffer();
// Add the manufacturer data to the advertisement publisher:
publisher.Advertisement.ManufacturerData.Add(manufacturerData);
publisher.Start();
近距离UUID
在对此进行测试时,我的iOS设备无法识别您提供的接近UUID。我猜这是因为你自己制作的,所以这个应用程序不知道要找什么。相反,我使用了来自这个答案的邻近UUID,它将Windows10设备标识为一个AirLocate iBeacon。
旗
Windows 10目前不允许开发人员设置蓝牙LE广告的标志。幸运的是,要使Windows设备被识别为iBeacon,您不需要这些标志!
发布于 2016-06-11 18:26:50
理想情况下,您希望将标志字节设置为0x1a,但其他值可能仍然有效。要设置的重要标志是通用可发现(0x02)。
您可以使用BluetoothLEAdvertisementFlags
是位值这里的枚举。
我的C#非常生疏,但是您可以尝试使用:publisher.Advertisement.Flags = 0x1A;
直接设置标志十六进制值。
https://stackoverflow.com/questions/37756441
复制相似问题