public MainPage() { InitializeComponent(); DataContext = this; _dispatcher = CoreWindow.GetForCurrentThread().Dispatcher; // Create the Bluetooth LE watcher from the Windows 10 UWP _watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active }; // Construct the Universal Bluetooth Beacon manager _beaconManager = new BeaconManager(); BeaconListView.ItemsSource = _beaconManager.BluetoothBeacons; // Simulate beacon info //#if DEBUG // var eddystoneBeacon = new Beacon(Beacon.BeaconTypeEnum.Eddystone); // eddystoneBeacon.BeaconFrames.Add(new TlmEddystoneFrame(0, 3100, (float)25.5, 2000, 1000)); // // Ranging Data 0xEE = -18dbM: needs unchecked syntax to cast constants, works without unchecked for runtime variables // // (sbyte)0x12 = +18dbM // // Sample values from: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.tx_power_level.xml // eddystoneBeacon.BeaconFrames.Add(new UidEddystoneFrame(unchecked((sbyte)0xEE), // new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A }, // new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 })); // eddystoneBeacon.BeaconFrames.Add(new UrlEddystoneFrame(220, "http://www.tieto.at")); // eddystoneBeacon.Rssi = -49; // eddystoneBeacon.BluetoothAddress = 0x0000e27ef189f6c4; // 3 // eddystoneBeacon.Timestamp = DateTimeOffset.Now; // _beaconManager.BluetoothBeacons.Add(eddystoneBeacon); //#endif }
public MainPage() { this.InitializeComponent(); DataContext = this; _dispatcher = CoreWindow.GetForCurrentThread().Dispatcher; // Create the Bluetooth LE watcher from the Windows 10 UWP _watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active }; // Construct the Universal Bluetooth Beacon manager _beaconManager = new BeaconManager(); BeaconListView.ItemsSource = _beaconManager.BluetoothBeacons; // Simulate beacon info //#if DEBUG // var eddystoneBeacon = new Beacon(Beacon.BeaconTypeEnum.Eddystone); // eddystoneBeacon.BeaconFrames.Add(new TlmEddystoneFrame(0, 3100, (float)25.5, 2000, 1000)); // eddystoneBeacon.BeaconFrames.Add(new UidEddystoneFrame(220, // new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A }, // new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 })); // eddystoneBeacon.BeaconFrames.Add(new UrlEddystoneFrame(220, "http://www.tieto.at")); // eddystoneBeacon.Rssi = -49; // eddystoneBeacon.BluetoothAddress = 0x0000e27ef189f6c4; // 3 // eddystoneBeacon.Timestamp = DateTimeOffset.Now; // _beaconManager.BluetoothBeacons.Add(eddystoneBeacon); //#endif }
//https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BluetoothAdvertisement/cs public BeaconManagerImpl() { this.beaconMgr = new BeaconManager(); this.beaconMgr.BluetoothBeacons.CollectionChanged += (sender, args) => { }; this.watcher = new BluetoothLEAdvertisementWatcher(); this.watcher.Received += (sender, args) => this.beaconMgr.ReceivedAdvertisement(args); // Begin of watcher configuration. Configure the advertisement filter to look for the data advertised by the publisher // in Scenario 2 or 4. You need to run Scenario 2 on another Windows platform within proximity of this one for Scenario 1 to // take effect. The APIs shown in this Scenario are designed to operate only if the App is in the foreground. For background // watcher operation, please refer to Scenario 3. // Please comment out this following section (watcher configuration) if you want to remove all filters. By not specifying // any filters, all advertisements received will be notified to the App through the event handler. You should comment out the following // section if you do not have another Windows platform to run Scenario 2 alongside Scenario 1 or if you want to scan for // all LE advertisements around you. // For determining the filter restrictions programatically across APIs, use the following properties: // MinSamplingInterval, MaxSamplingInterval, MinOutOfRangeTimeout, MaxOutOfRangeTimeout // Part 1A: Configuring the advertisement filter to watch for a particular advertisement payload // First, let create a manufacturer data section we wanted to match for. These are the same as the one // created in Scenario 2 and 4. //var manufacturerData = new BluetoothLEManufacturerData(); //// Then, set the company ID for the manufacturer data. Here we picked an unused value: 0xFFFE //manufacturerData.CompanyId = 0xFFFE; //// Finally set the data payload within the manufacturer-specific section //// Here, use a 16-bit UUID: 0x1234 -> {0x34, 0x12} (little-endian) //var writer = new DataWriter(); //writer.WriteUInt16(0x1234); //// Make sure that the buffer length can fit within an advertisement payload. Otherwise you will get an exception. //manufacturerData.Data = writer.DetachBuffer(); //// Add the manufacturer data to the advertisement filter on the watcher: //watcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(manufacturerData); //// Part 1B: Configuring the signal strength filter for proximity scenarios //// Configure the signal strength filter to only propagate events when in-range //// Please adjust these values if you cannot receive any advertisement //// Set the in-range threshold to -70dBm. This means advertisements with RSSI >= -70dBm //// will start to be considered "in-range". //watcher.SignalStrengthFilter.InRangeThresholdInDBm = -70; //// Set the out-of-range threshold to -75dBm (give some buffer). Used in conjunction with OutOfRangeTimeout //// to determine when an advertisement is no longer considered "in-range" //watcher.SignalStrengthFilter.OutOfRangeThresholdInDBm = -75; //// Set the out-of-range timeout to be 2 seconds. Used in conjunction with OutOfRangeThresholdInDBm //// to determine when an advertisement is no longer considered "in-range" //watcher.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(2000); // By default, the sampling interval is set to zero, which means there is no sampling and all // the advertisement received is returned in the Received event }
/** * Default constructor **/ public MainPage() { this.InitializeComponent(); // init beacon manager beaconManager = new BeaconManager(); // create and start the (W10 UWP) BLE watcher watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active }; // trigger following method when we receive data watcher.Received += WatcherOnReceived; // start watching watcher.Start(); }
public BeaconManagementService() { _dispatcher = CoreWindow.GetForCurrentThread().Dispatcher; // Create the Bluetooth LE watcher from the Windows 10 UWP _watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active }; // Create the Bluetooth LE publisher from the Windows 10 UWP _publisher = new BluetoothLEAdvertisementPublisher(); // Construct the Universal Bluetooth Beacon manager _beaconManager = new BeaconManager(); BeaconsList = _beaconManager.BluetoothBeacons; _resourceLoader = ResourceLoader.GetForCurrentView(); StartScanning(); }
public void Start() { // Construct the Universal Bluetooth Beacon manager _beaconManager = new BeaconManager(); // Create & start the Bluetooth LE watcher from the Windows 10 UWP _watcher = new BluetoothLEAdvertisementWatcher {ScanningMode = BluetoothLEScanningMode.Active}; _watcher.Received += WatcherOnReceived; _watcher.Start(); }