Drake
Drake

Reputation: 2703

Invalid advertisement payload detected

I am trying to advertise a UUID in my UWP app with BLE, so other devices can scan for it and find it. Here is my code to advertise:

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

It throws this exception when I call Start():

The data is invalid - Invalid advertisement payload detected

Upvotes: 0

Views: 704

Answers (1)

Mike Petrichenko
Mike Petrichenko

Reputation: 1024

As described in MSDN: https://learn.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.advertisement.bluetoothleadvertisementpublisher

The UUID advertisement is not supported

The following advertisement types are system-reserved and are not allowed:

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)

Upvotes: 3

Related Questions