首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将BluetoothLEAdvertisement.Flags设置为C#中的iBeacon广告

将BluetoothLEAdvertisement.Flags设置为C#中的iBeacon广告
EN

Stack Overflow用户
提问于 2016-06-10 20:11:32
回答 2查看 2.5K关注 0票数 0

MS提供了样本来发送和接收蓝牙低能广告。我看到这个非常有用的答案破坏了iBeacon包。还有一个例子将BluetoothLEAdvertisement.ManufacturerData设置为ibeacon标准。

我可以问如何设置BluetoothLEAdvertisement的旗帜吗?例如,将值设置为: 02-01-06。

谢谢

编辑1:这是代码:

代码语言:javascript
运行
复制
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膝上型计算机将为原始数据包做广告,如下所示:

代码语言:javascript
运行
复制
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:

代码语言:javascript
运行
复制
if [[ $packet =~ ^04\ 3E\ 2A\ 02\ 01\ .{26}\ 02\ 01\ .{14}\ 02\ 15 ]]; then

因此,之前的原始数据包将不会被识别,因为缺少标志部分。我想知道我是否可以用旗子做广告,比如:

代码语言:javascript
运行
复制
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中的扫描脚本。

EN

Stack Overflow用户

发布于 2016-06-13 19:28:21

iBeacon on Windows

以下代码在Windows 10计算机上发布iBeacon:

代码语言:javascript
运行
复制
// 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,您不需要这些标志!

票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37756441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档