Обнаружена неверная полезная нагрузка рекламы - PullRequest
0 голосов
/ 26 февраля 2019

Я пытаюсь объявить UUID в своем приложении UWP с помощью BLE, чтобы другие устройства могли его найти и найти.Вот мой код для рекламы:

    // 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():

Данные недействительны - обнаружена недопустимая полезная нагрузка рекламы

1 Ответ

0 голосов
/ 26 февраля 2019

Как описано в MSDN: https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.advertisement.bluetoothleadvertisementpublisher

Объявление 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)
...