首页 > 解决方案 > UWP BluetoothLEAdvertisementWatcherTrigger not triggering with service uuid filter

问题描述

An in-process background task with trigger is being registered:

var trigger = new BluetoothLEAdvertisementWatcherTrigger();
trigger.AdvertisementFilter.Advertisement.ServiceUuids.Add(GattServiceUuids.CyclingSpeedAndCadence);

... more background code left out for simplicity ...

Unfortunately this never gets triggered when I run the app in Do not launch, but debug my code when it starts option.

Whenever I run the app normally with an advertisements watcher, I do get this info (so the service ID I am filtering is correct):

Local name:  'mydevice1234'
Company:     ''
Service ids: '00001816-0000-1000-8000-00805f9b34fb;0000180f-0000-1000-8000-00805f9b34fb'

Unfortunately I cannot use the company ID in the filter since the company is empty on advertisements...

Any ideas why this is not triggering? The documentation only mentions the company filter, but I cannot use that.

Update 2019-10-10:

To clarify: I can perfectly communicate with the bluetooth device.

Let me try to explain what I want. Whenever the app detects that it's not running (using a background task) but sees the device has come on-line, then it should show a message: do you want to start the app? This way the user can be reminded to start the companion app.

The background advertisements watcher, based on service ids without a company, seems not to work (although it should be possible if I understand the Bluetooth standards / documentation correctly).

标签: uwpbluetoothbluetooth-lowenergy

解决方案


根据蓝牙规范,制造商数据不是强制性的。从我的角度来看,这并不重要。

@geertvanhorrik,您提到前台观察者工作正常。我怀疑问题出在Do not launch, but debug my code when it starts option上。为了确认这一点,是否可以使用任何蓝牙协议数据包分析器(如wireshark)来验证BackgroundWatcher 是否正在接收数据?

至少可以确认 Backgroundwatcher 正在接收数据。


推荐阅读