Comments (10)
Hi @Auto72,
I'm the friendly issue checker.
It seems like (100.00 %) you haven't used our issue template 😢 I think it is very frustrating for the repository owners, if you ignore them.
If you think it's fine to make an exception, just ignore this message.
But if you think it was a mistake to delete the template, please close the issue and create a new one.
Thanks!
from dotnet-bluetooth-le.
I wonder if the DeviceAdvertised
event
is effected by the Adapter.ScanMatchMode
. I wouldn't think so but you might try setting Adapter.ScanMatchMode = STICKY
and see if that avoids your device from processing duplicate packets from the same device as it does during a Scan.
Otherwise you might try setting Adapter.ScanMode = Passive, but i really doubt that is going to have any impact on the DeviceAdvertised
event
either.
That said i don't believe DeviceAdvertised
is called back on the UI thread, so you might look at other ways you might be tying up the UI thread unwittingly, but honestly I'm not confident in any of the advice im giving you here will help so...
from dotnet-bluetooth-le.
Thanks for your tips, I will try them and report here the result.
NOTE: On Android and iOS I found the MainThread.IsMainThread = true inside the event DeviceAdvertised, but not on Windows. I tried this.
private void Adapter_DeviceAdvertised(object? sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e)
{
Debub.WriteLine($"IsMainThread: {MainThread.IsMainThread}"); // returns True on Android and iOS, but not on Windows.
}
from dotnet-bluetooth-le.
I used to set Adapter.ScanMode = ScanMode.LowLatency in Xamarin with no problem.
In .NET MAUI I have the issue reported above on Android.
Adapter.ScanMatchMode is and has been always STICKY.
Using Adapter.ScanMode = ScanMode.Balanced is better, but sometimes the behaviour is similar to ScanMode.LowLatency
With Adapter.ScanMode = Passive I don't receive any scan device.
from dotnet-bluetooth-le.
e is and has been always STICKY.
Using Adapter.ScanMode = ScanMode.Balanced is better, but sometimes the behaviour is similar to ScanMode.LowLatency
With Adapter.ScanMode = Passive I don't receive any scan device.
Unsure. im able to get good response both on windows and Android
Perhaps post a gist and someone might be able to comment...
from dotnet-bluetooth-le.
Are you saying that the DeviceAdvertised
event on Android is only raised on the main thread in MAUI, but not in Xamarin? Or are you just saying that the performance is worse with MAUI?
from dotnet-bluetooth-le.
How to handle this situation probably depends a bit on your kind of setup and what you're trying to achieve.
First question: Are all of these advertisements even relevant for you? If not, you should probably use a scan filter to reduce the number of advertisements you have to process.
Then, of course, you should do as little work as possible in response to an advertisement (but you're probably already doing that, I hope).
And finally you can try to do the processing in the background, e.g. via a ThreadPool
(which re-uses the threads in the pool and avoids the overhead of creating a new thread for each task).
AFAICS the library does nothing specific to put these events on the main thread, but just passes them on as they come from the OS.
from dotnet-bluetooth-le.
Are you saying that the
DeviceAdvertised
event on Android is only raised on the main thread in MAUI, but not in Xamarin? Or are you just saying that the performance is worse with MAUI?
No, I'm saying that in Xamarin as in .NET MAUI the DeviceAdvertised
event is raised on the main thread.
While in Xamarin the event is raised 9 times per seconds, in .NET MAUI it is raised 106 times per seconds.
I tested the same environment with Xamarin App and .NET MAUI App.
In Xamarin the advertisements are only for my device, in .NET MAUI from all kind of devices.
The advertising interval for my BLE device is 2 or 3 times per second.
from dotnet-bluetooth-le.
How to handle this situation probably depends a bit on your kind of setup and what you're trying to achieve.
First question: Are all of these advertisements even relevant for you? If not, you should probably use a scan filter to reduce the number of advertisements you have to process.
Then, of course, you should do as little work as possible in response to an advertisement (but you're probably already doing that, I hope).
And finally you can try to do the processing in the background, e.g. via a
ThreadPool
(which re-uses the threads in the pool and avoids the overhead of creating a new thread for each task).AFAICS the library does nothing specific to put these events on the main thread, but just passes them on as they come from the OS.
First answer:
No, I'm interested only in my devices, that have the name that start with a prefix.
I see how to put a filter, but it seems I can't specify a mask, like "Prefix*".
https://github.com/dotnet-bluetooth-le/dotnet-bluetooth-le#scan-filtering
I use the DeviceAdvertised event for two reasons:
a) I get the device before the event DeviceDiscovered is raised, so I can show it soon.
b) I get the value of RSSI updated.
Sure, I tried with Task.Run() but it doesn't work.
I think the library put all the advertisements in a queue and raise the event until the queue is empty, even if the scan has been stopped.
from dotnet-bluetooth-le.
I reviewed my code and now I used Task.Run() also in the DeviceDiscovered event and other adjustments.
I set Adapter.ScanMode = Balanced for Android.
Now seems a little bit better, but anyway it raises 90 events per minute.
I solved setting a filter by ServiceUuids.
var scanFilterOptions = new ScanFilterOptions { ServiceUuids = [Guid.Parse(MyStringGUID)] };
adapter.StartScanningForDevicesAsync(scanFilterOptions);
Thanks.
from dotnet-bluetooth-le.
Related Issues (20)
- [BUG] NET MAUI on iOS, I read a wrong name connectiong to a Linux device HOT 8
- Can't detect device HOT 10
- when "OnConnectionStateChange: GattStatus: InsufficientAuthorization" is shown, the ble will hang forever HOT 5
- Manufacturer data packet is missing from device on iOS HOT 4
- Cannot use the package with Avalonia Cross Platform Project HOT 7
- ConnectToKnownDeviceAsync is giving null as device name HOT 2
- Regarding Plugin.BLE Connection Event HOT 1
- Plugin.BLE - Issue Regarding ambiguous connection HOT 2
- limit of bluetooth device can be connected simultaneous HOT 8
- Ble connected Device Get Service always return null HOT 2
- [WinUI] Adapter.DeviceConnected event is triggered n+1 times upon each subsequent Device Disconnect/Connect cycle HOT 7
- Need to be able to register for notification from characteristics that is only INDICATE HOT 9
- WinUI Call to `DisconnectDeviceAsync` may not complete. HOT 5
- Windows: Check OS version runtime HOT 5
- Bluetooth stack breaks when trying connect on phone boot HOT 2
- It doesn't work with android 14 HOT 1
- It doesn't work with android 14 HOT 5
- Determining feature support/availbility RSSI update others? HOT 1
- Windows - Run Discover Scan twice cause Disconnection fail HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotnet-bluetooth-le.