Search code examples
c#bluetoothbluetooth-lowenergyuwp-xaml

How to Advertise More Than 31 Bytes Using Bluetooth Advertisement Publishers


I am working on a sensor simulator for testing purposes. The sensor I want to simulate is a BlueMaestro humidity and temperature sensor.

I need to advertise 57 bytes, but I am currently unable to send more than 31 bytes. How can I advertise more data using Bluetooth advertisement publishers?

Any guidance or examples would be greatly appreciated.

Thanks


Solution

  • According to the document, this is the default behavior.

    When a service is both Discoverable and Connectable, the system will add the Service Uuid to the advertisement packet. There are only 31 bytes in the Advertisement packet and a 128-bit UUID takes up 16 of them!

    The max payload for a single advertisement packet can expand to 0-254 bytes with Bluetooth 5.0. If you want to send more data than 31 bytes using Bluetooth advertisement publishers, you have to check if the system supports BLE 5.0.

    Use the API BluetoothAdapter.IsExtendedAdvertisingSupported to check whether the adapter supports the 5.0 Extended Advertising format. If the adapter supported extended advertising, then you could send more data than 31 bytes.

    Besides, if you want to send an advertisement using the BluetoothLEAdvertisementPublisher. You need to enable it using Property BluetoothLEAdvertisementPublisher.UseExtendedAdvertisement.