我正在尝试用BLE在我的UWP应用中发布UUID,以便其他设备可以扫描并找到它。这是我要宣传的代码:
// Start advertisement
if (_publisher == null)
{
_publisher = new BluetoothLEAdvertisementPublisher();
}
// We need to add some payload to the advertisement. A publisher without any payload
// or with invalid ones cannot be started. We only need to configure the payload once
// for any publisher.
// Add a manufacturer-specific section:
// First, let create a manufacturer data section
var manufacturerData = new BluetoothLEManufacturerData();
// Then, set the company ID for the manufacturer data. Here we picked an unused value: 0xFFFE
manufacturerData.CompanyId = 0xFFFE;
// 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();
UInt16 uuidData = 0x1234;
writer.WriteUInt16(uuidData);
// Make sure that the buffer length can fit within an advertisement payload. Otherwise you will get an exception.
manufacturerData.Data = writer.DetachBuffer();
// Add the manufacturer data to the advertisement publisher:
_publisher.Advertisement.ManufacturerData.Add(manufacturerData);
string serviceUuid = $"11111111-1234-1234-1234-000000000000";
_advertisementUuid = new Guid(serviceUuid);
_publisher.Advertisement.ServiceUuids.Add(_advertisementUuid);
_publisher.StatusChanged -= Publisher_StatusChanged;
_publisher.StatusChanged += Publisher_StatusChanged;
_publisher.Start();
当我致电Start()
时,它将引发此异常:
数据无效-检测到无效的广告有效载荷
答案 0 :(得分:1)
不支持UUID广告
以下广告类型是系统保留的,并且不允许:
Flags (0x01)
Incomplete List of 16-bit Service UUIDs (0x02)
Complete List of 16-bit Service UUIDs (0x03)
Incomplete List of 32-bit Service UUIDs (0x04)
Complete List of 32-bit Service UUIDs (0x05)
Incomplete List of 128-bit Service UUIDs (0x06)
Complete List of 128-bit Service UUIDs (0x07)
Shortened Local Name (0x08)
Complete Local Name (0x09)
Tx Power Level (0x0A)
Class of Device (0x0D)
Simple Pairing Hash C192 (0x0E)
Simple Pairing Randomizer R192 (0x0F)
Security Manager TK Values (0x10)
Security Manager Out-of-Band Flags (0x11)
Slave Connection Interval Range (0x12)
List of 16-bit Service Solicitation UUIDs (0x14)
List of 32-bit Service Solicitation UUIDs (0x1F)
List of 128-bit Service Solicitation UUIDs (0x15)
Service Data 16-bit UUID (0x16)
Service Data 32-bit UUID (0x20)
Service Data 128-bit UUID (0x21)
Public Target Address (0x17)
Random Target Address (0x18)
Appearance (0x19)
Advertising Interval (0x1A)
LE Bluetooth Device Address (0x1B)
LE Role (0x1C)
Simple Pairing Hash C256 (0x1D)
Simple Pairing Randomizer R256 (0x1E)
3D Information Data (0x3D)