1
votes

I try to scan BLE devices in my Windows 10 IOT background (headless) app running on Raspberry PI 3.

I also tried to use BluetoothLEAdvertisementWatcher in a headed app (with UI) on the same RaspBerry PI machine and it worked.

My headless app is the simplest as it can be:

public sealed class StartupTask : IBackgroundTask
{
    private readonly BluetoothLEAdvertisementWatcher _bleWatcher = 
        new BluetoothLEAdvertisementWatcher();

    public void Run(IBackgroundTaskInstance taskInstance)
    {
        _bleWatcher.Received += _bleWatcher_Received;
        _bleWatcher.ScanningMode = BluetoothLEScanningMode.Active;
        _bleWatcher.Start();
    }

    private void _bleWatcher_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
    {

    }
}

_bleWatcher_Received is never hit. Capabilities are set (Bluetooth, Internet, Proximity).

What is the problem? What do I miss?

1
Can you be more clear? - Joe Phillips
Thanks Joe. What do you mean? - Tom
Did you get the headed app working on the rPi or on a different machine? Be more specific please - Joe Phillips
Thanks, on the same machine. I updated my question. - Tom

1 Answers

1
votes

You app shuts down when the run method completes. That's why _bleWatcher_Received is never hit.

To prevent you app from exiting you need call the “GetDeferral” method like this:

public void Run(IBackgroundTaskInstance taskInstance)
{
    deferral = taskInstance.GetDeferral();

    //YOUR CODE HERE
}

For more information please reference "Developing Background Applications".