none
When UWP BLE advertising watcher is started its status is Aborted RRS feed

  • Question

  • Whenever I start BluetoothLEAdvertisementWatcher from UWP application  its status is aborte.

    Using same functionality in Console application is without a problem (required libraries are included, of course). When I want to pair with BLE device, I use DeviceWatcher from UWP application - also without the problem. OS is Win10, and VS2015 Community is used.

    The application behaviour is the same on different development machine, therefore I don't think it the problem with or with installation.

    There are two recommendations on the web:

    1. to enable Bluetooth

    2. to check capabilities

    None of them provided results.

    To ilustrate the problem, I made a new UWP project with Bluetooth included in capabilities:

       <Capabilities>
       <Capability Name="internetClient" />
       <DeviceCapability Name="bluetooth" />
       </Capabilities>

    There are buttons: Start (to start watcher), Stop (to stop watcher) and View (to display state of watcher), and TextBlock used for displaying status of BluetoothLEAdvertisementWatcher on MainPage. Code is provided:

    public sealed partial class MainPage : Page
        {
            private BluetoothLEAdvertisementWatcher watcher = null;
    
            public MainPage()
            {
                this.InitializeComponent();
    
                watcher = new BluetoothLEAdvertisementWatcher();
                watcher.ScanningMode = BluetoothLEScanningMode.Active;
    
                textBlock.Text = watcher.Status.ToString();
            }
    
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                watcher.Received += OnAdvertisementReceived;
    
                watcher.Stopped += OnAdvertisementWatcherStopped;
            }
    
    
            private void StopButton_Click(object sender, RoutedEventArgs e)
            {
                watcher.Stop();
            }
    
            private async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
            {
    
                await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    textBlock.Text = "rcvd" + watcher.Status.ToString();
                });
            }
    
            private async void OnAdvertisementWatcherStopped(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementWatcherStoppedEventArgs eventArgs)
            {
                // Notify the user that the watcher was stopped
                await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    textBlock.Text = "stopped:" + watcher.Status.ToString();
                });
            }
    
            private void buttonStart_Click(object sender, RoutedEventArgs e)
            {
                watcher.Start();
                textBlock.Text = watcher.Status.ToString();
            }
            private void buttonStop_Click(object sender, RoutedEventArgs e)
            {
                watcher.Stop();
                textBlock.Text = watcher.Status.ToString();
            }
    
            private void buttonView_Click(object sender, RoutedEventArgs e)
            {
                textBlock.Text = watcher.Status.ToString();
            }
        }

    When the program is started, BluetoothLEAdvertisementWatcher status is Created.

    After pressing Start button, after finishing event handler buttonStart_Click, event OnAdvertisementWatcherStopped is triggered and watcher status is Aborted.

    When I comment usage of watcher.Stopped += OnAdvertisementWatcherStopped, in the buttonStart_Click, status Started is displayed. After clicking on View button, status is Aborted.

    Any suggestion what can be done to have the normal behaviour of BluetoothLEAdvertisementWatcher in UWP app?

    Did I miss some configuration setting, or some initialization in code, or... ?

    Friday, January 27, 2017 10:10 PM

Answers

  • Hello,

    You mentioned Win10, so I am going to assume the latest Insider Preview build, but the instructions generally apply to all just the UX names may vary.

    The first thing I would check is that your application has access in the Settings, Privacy, Other Devices, "Choose apps that can sync with devices" setting. Ensure the app is listed and enabled there.

    The next thing I would try is download and build our official sample for the scenario. You should be able to remove the example manufacture filters and still have it work. The sample is here: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BluetoothAdvertisement

    If that sample does not work for you please use Feedback Hub to collect the data I need using the sample. 

    Use a title like "Bluetooth Advertisement Monitoring does work with Sample on {Name of Radio Adapter}" so I can search for it and find it. You can find the radio adapter name in Device Manager. Mine for example is "Marvell AVASTART Bluetooth Radio Adapter".

    Ensure you select it's a problem, select category, "Hardware, Devices, and Drivers" then "Bluetooth - Low Energy and Wearables". Then under "Show us the problem...." "Bluetooth - Low Engery and Wearables (Default)" will be selected. You select "Begin Monitoring".  Launch your application and demonstrate the failure. Then click "Stop monitoring" and Submit the feedback. Reply to the thread and I will report my findings.

    • Marked as answer by Mihailo S Saturday, January 28, 2017 5:03 PM
    Saturday, January 28, 2017 2:50 AM

All replies

  • Hello,

    You mentioned Win10, so I am going to assume the latest Insider Preview build, but the instructions generally apply to all just the UX names may vary.

    The first thing I would check is that your application has access in the Settings, Privacy, Other Devices, "Choose apps that can sync with devices" setting. Ensure the app is listed and enabled there.

    The next thing I would try is download and build our official sample for the scenario. You should be able to remove the example manufacture filters and still have it work. The sample is here: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BluetoothAdvertisement

    If that sample does not work for you please use Feedback Hub to collect the data I need using the sample. 

    Use a title like "Bluetooth Advertisement Monitoring does work with Sample on {Name of Radio Adapter}" so I can search for it and find it. You can find the radio adapter name in Device Manager. Mine for example is "Marvell AVASTART Bluetooth Radio Adapter".

    Ensure you select it's a problem, select category, "Hardware, Devices, and Drivers" then "Bluetooth - Low Energy and Wearables". Then under "Show us the problem...." "Bluetooth - Low Engery and Wearables (Default)" will be selected. You select "Begin Monitoring".  Launch your application and demonstrate the failure. Then click "Stop monitoring" and Submit the feedback. Reply to the thread and I will report my findings.

    • Marked as answer by Mihailo S Saturday, January 28, 2017 5:03 PM
    Saturday, January 28, 2017 2:50 AM
  • Thank you A LOT Frank for your quick and detailed answer.

    The solution in my case was to change settings of my test application.

    I have to admit that this is the first programming forum where I find this explanation provided, so I hope that it will be useful for someone else.

    Saturday, January 28, 2017 5:07 PM
  • My pleasure. I wish you the best in your endeavors. I'll review our docs on this and see if we can improve them.
    Sunday, January 29, 2017 12:23 AM
  • Hi,

    I have already reported the BLEWatcher hang-up problem with my and the MS sample application in Win 10 IoT on Raspberry Pi 3 SBC. Please take a look at my description. I will appreciate your advice how to solve this problem. Here is the link to my original question:

    https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/358bde44-502c-43fb-990b-47cb7a9db560/uwp-application-hangsup-on-blewatcher-restart?forum=wdk

    Thanks.


    • Edited by Paul_I Thursday, February 1, 2018 5:45 PM
    Thursday, February 1, 2018 5:43 PM