【发布时间】:2016-06-10 20:11:32
【问题描述】:
MS 提供了samples 来发送和接收低功耗蓝牙广告。 我看到this very helpful answer 分解了 iBeacon 数据包。还有an example 用于将BluetoothLEAdvertisement.ManufacturerData 设置为ibeacon 标准。
请问如何设置BluetoothLEAdvertisement 的Flags? 例如将值设置为: 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 Networks 的代码here。您可以在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 中的扫描脚本。
【问题讨论】:
标签: c# bluetooth windows-10 bluetooth-lowenergy ibeacon