Created
April 24, 2021 22:36
-
-
Save hasan-hasanov/1cccd2aeb4f6588681520889dcdb84aa to your computer and use it in GitHub Desktop.
Bluetooth Low Energy Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program | |
| { | |
| static async Task Main(string[] args) | |
| { | |
| var watcher = new BluetoothLEAdvertisementWatcher(); | |
| watcher = new BluetoothLEAdvertisementWatcher() | |
| { | |
| ScanningMode = BluetoothLEScanningMode.Passive | |
| }; | |
| watcher.Received += Watcher_Received; | |
| watcher.Start(); | |
| await Task.Delay(Timeout.Infinite); | |
| } | |
| private static async void Watcher_Received( | |
| BluetoothLEAdvertisementWatcher sender, | |
| BluetoothLEAdvertisementReceivedEventArgs args) | |
| { | |
| var device = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress); | |
| if (device != null) | |
| { | |
| Console.WriteLine(device.BluetoothAddress); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment