void Adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { if (DeviceList.Contains(e.Device) == false && e.Device.Name?.Contains("esp32") == true) { DeviceList.Add(e.Device); } }
void Adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { if (!string.IsNullOrEmpty(e.Device.Name)) { deviceList.Add(e.Device); } }
void Adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { System.Diagnostics.Debug.WriteLine($"Device detected {e.Device.Name} {e.Device.Id}"); var board = new OWBoard() { Name = e.Device.Name, ID = e.Device.Id.ToString(), IsAvailable = true, Device = e.Device, }; _foundInLastScan.Add(board); var boardIndex = Boards.IndexOf(board); if (boardIndex == -1) { Boards.Add(board); } else { // Its odd that we set the name again, but when a board is just powered on its name is "Onewheel", not "ow123456" Boards[boardIndex].Name = e.Device.Name; Boards[boardIndex].IsAvailable = true; Boards[boardIndex].Device = e.Device; } }
/// <summary> /// When a device is found, a check is run to see if the name of the device /// matches the name of the Arduino device. If so, proper connection is established. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { var adapter = CrossBluetoothLE.Current.Adapter; if (e.Device.Name != "SenProBLE") { return; } try { infoText.Text = "Device found, attempting connection..."; adapter.ConnectToDeviceAsync(e.Device); adapter.DeviceConnected += (s, a) => { Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { connectButton.Enabled = false; guidConnectButton.Enabled = false; subscribeButton.Enabled = true; infoText.Text = "Connection Established."; }); adapter.StopScanningForDevicesAsync(); }; } catch (Exception exception) { Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { infoText.Text = "Failed to establish connection."; }); } }
/// <summary> /// This handler fires when the application loses connection with the Arduino, /// and fires up the Reconnect activity. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Adapter_ConnectionLost(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { currentlyListening = false; var reconnectActivity = new Intent(this, typeof(ReconnectActivity)); reconnectActivity.PutExtra("GUID", deviceId); StartActivity(reconnectActivity); }
private void Adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { Debug.WriteLine($"Bluetooth device discovered: {e.Device.Name}"); if (!this.devices.Any(d => d.Name == e.Device.Name)) { this.devices.Add(e.Device); } }
private void Adapter_DeviceDisconnected(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { Device.BeginInvokeOnMainThread(new Action(() => { BtImage.Source = "bt_off.png"; })); adapter.StartScanningForDevicesAsync(); }
private void OnDeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs args) { DeviceInfomation entry = new DeviceInfomation(); entry.DeviceName = args.Device.Name; entry.UUID = args.Device.Id; entry.RSSI = args.Device.Rssi; RaiseEvent <DeviceFinderArgs>(OnSearchCompleted, this, new DeviceFinderArgs(entry)); }
void Adapter_DeviceConnected(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { System.Diagnostics.Debug.WriteLine($"Device connected {e.Device.Name} {e.Device.Id}"); if (e.Device == _selectedBoard.Device && _selectedBoard != null) { Device.BeginInvokeOnMainThread(async() => { await Navigation.PushAsync(new BoardPage(_selectedBoard)); Hud.Dismiss(); }); } }
private async void DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { ESense device = new ESense(e.Device); bool valid = await device.ValidateServicesAsync(); if (valid) { EarableEventArgs args = new EarableEventArgs(device); EarableDiscovered.Invoke(this, args); } }
public static void Adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { bleDeviceNo++; Debug.WriteLine($"The bluetooth device discovered No: {bleDeviceNo}"); Debug.WriteLine($"The bluetooth device discovered ID {e.Device.Id}"); Debug.WriteLine($"The bluetooth device discovered Name {e.Device.Name}"); Debug.WriteLine($"The bluetooth device discovered NativeDevice {e.Device.NativeDevice}"); Debug.WriteLine($"The bluetooth device discovered RSSI {e.Device.Rssi}"); Debug.WriteLine($"The bluetooth device discovered State {e.Device.State}"); Debug.WriteLine($"The bluetooth device discovered AdvertisementRecords {e.Device.AdvertisementRecords.ToString()}"); }
private void _adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { IDevice device = e.Device; var androidDev = (Android.Bluetooth.BluetoothDevice)device.NativeDevice; string name = string.IsNullOrWhiteSpace(androidDev.Name) ? "<No Name>" : androidDev.Name; _logger.Log($"Device discovered. Name: {name} Address: {androidDev.Address}", Category.Debug, Priority.None); foreach (var record in device.AdvertisementRecords) { if (record.Type == AdvertisementRecordType.UuidsComplete128Bit) { Guid guid = Helper.ByteArrayToGuid(record.Data); if (Constants.ExtractorServiceUuid.Equals(guid) || Constants.GoPlusServiceUuuid.Equals(guid) || Constants.SpotaServiceUuid.Equals(guid)) { _logger.Log($"GO Plus Discovered!", Category.Info, Priority.None); GoPlus pgp = new GoPlus() { Name = androidDev.Name, BtAddress = androidDev.Address }; _devicesFound.Add(pgp, device); _aggregator.GetEvent <PrismEvents.GoPlusFoundEvent>().Publish(pgp); } } else if (record.Type == AdvertisementRecordType.UuidsComplete16Bit) { if (string.Compare(Constants.GoPlusName, androidDev.Name) == 0) { if (record.Data != null && record.Data.Length > 1 && record.Data[0] == Constants.SuotaAdvertisementUuid[0] && record.Data[1] == Constants.SuotaAdvertisementUuid[1]) { _logger.Log($"GO Plus SUOTA Discovered!", Category.Info, Priority.None); GoPlus pgp = new GoPlus() { Name = androidDev.Name, BtAddress = androidDev.Address }; _devicesFound.Add(pgp, device); _aggregator.GetEvent <PrismEvents.GoPlusFoundEvent>().Publish(pgp); } } } } }
private void BleAdapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { if (e.Device.Name != null) { if (e.Device.Name.ToLower().Contains("droplet") && IsBleScanning) { var devBle = new _bleDevice(); devBle.Name = e.Device.Name; devBle.IsConnected = false; devBle.Uuid = e.Device.Id; bleDevices.Add(devBle); } } }
private async void _adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { if (_status == Status.STATUS_SCANNING_FOR_DEVICE) { _log("_adapter_DeviceDiscovered", $"Device {e.Device.Name}"); if (e.Device.Name == _deviceName) { try { _device = e.Device; await _adapter.ConnectToDeviceAsync(_device); _serviceHR = await e.Device.GetServiceAsync(SERVICE_HEARTRATE); _characteristicHR = await _serviceHR?.GetCharacteristicAsync(CHARACTERISTIC_HEARTRATE); _serviceBattery = await e.Device.GetServiceAsync(SERVICE_BATTERY); if (_serviceBattery != null) { _characteristicBatteryLevel = await _serviceBattery?.GetCharacteristicAsync(CHARACTERISTIC_BATTERYLEVEL); } else { _characteristicBatteryLevel = null; } if (_characteristicHR != null) { _status = Status.STATUS_CONNECTED; _cancelScanningForDevice(); _characteristicHR.ValueUpdated += CharacteristicHR_ValueUpdated; await _characteristicHR.StartUpdatesAsync(); _log("_adapter_DeviceDiscovered", $"Device {e.Device.Name} STARTED"); } } catch (Exception err) { _log("_adapter_DeviceDiscovered", err.Message); } } } }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously async void Adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { try { if ((!String.IsNullOrWhiteSpace(e.Device.Name)) && e.Device.Name.StartsWith("SOTW_", StringComparison.Ordinal)) { Log.Information($"Found device {e.Device.Id} -- {e.Device.Name}"); var _soterDevice = new SoterDeviceBle(e.Device); Devices.Add(_soterDevice); } } catch (Exception ex) { Log.Error(ex.ToString()); } }
// We use the BLE library adapter to set up our custom peripheral. private void BleAdapter_DeviceConnected(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { if (e.Device.Name.ToLower().Contains("jamar")) { Console.WriteLine("connected to device " + e.Device.Name); var HandGripDevice = e.Device; Task.Delay(500).Wait(); if (HandGripDevice.GetServicesAsync().Result.Count == 0) { bleAdapter.DisconnectDeviceAsync(HandGripDevice); HandGripDevice.Dispose(); HandGripDevice = null; return; } HandGripDevice.GetServiceAsync(NordicUARTService).Result.GetCharacteristicAsync(NordicUARTTXCharacteristic).Result.ValueUpdated += TX_Updated; HandGripDevice.GetServiceAsync(NordicUARTService).Result.GetCharacteristicAsync(NordicUARTTXCharacteristic).Result.StartUpdatesAsync(); } }
private async void Adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { if (e.Device.NativeDevice.ToString() == "D0:5F:B8:1A:34:F0") { await adapter.StopScanningForDevicesAsync(); device = e.Device as IDevice; try { await adapter.ConnectToDeviceAsync(device); } catch { isConnected = false; } } }
private async void Adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { try { var item = e.Device.GetType().GetProperty("BluetoothDevice").GetValue(e.Device); var address = item.GetType().GetProperty("Address").GetValue(item).ToString(); var name = item.GetType().GetProperty("Name").GetValue(item).ToString(); if (name.ToLower().Contains("sensor")) { storage.GUID = e.Device.Id.ToString(); bluetooth.UpdateDevice(address, name); await adapter.ConnectToDeviceAsync(e.Device); } } catch (Exception ef) { Crashes.TrackError(ef); } }
private void DeviceWatcher_Added(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs args) { Debug.WriteLine("Device watcher detected : " + args.Device.Name); int indexer = index++; if (args.Device.Name == string.Empty || mVisibleDevices == null) { return; } MutexBlock(() => { mVisibleDevices.Clear(); foreach (var item in mAdapter.DiscoveredDevices) { AddUniqueItem(new UnPairedDeviceBLE(item)); } }, (indexer.ToString() + " Adding")); TriggerListUpdate(); }
async void discoveredDevice(object s, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs a) { //BorderColor="#777777" BorderRadius="10" BorderWidth="2" BackgroundColor="#FAFAFA" if (!currentSchakelaars.Any(sc => sc.DeviceGUID == a.Device.Id.ToString())) { deviceList.Add(a.Device); Button button = new Button() { Text = a.Device.Name ?? a.Device.NativeDevice.ToString(), FontSize = 30, Padding = new Thickness(0, 10), Margin = new Thickness(10, 0), TextTransform = TextTransform.None, BorderColor = Color.FromHex("#777777"), BorderWidth = 2, BackgroundColor = Color.FromHex("#FAFAFA"), CornerRadius = 2, TextColor = Color.FromHex("#f8a54a") }; button.Clicked += (z, x) => DeviceButtonClicked(z, x, a.Device); DevicesStack.Children.Add(button); } }
private void OnDeviceAdvertised(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { var message = e.Device.AdvertisementRecords.FirstOrDefault(_ => _.Data.Length == 26); if (message != null) { var tm = BitConverter.ToString(message.Data.Take(2).ToArray()); if (tm != "99-04")//Ruuvi manufacturer id (seems reversed but is working for now) { return; } var tagMessage = RuuviDf5Decoder.DecodeMessage(message.Data); Debug.WriteLine(tagMessage.MacAddress); Debug.WriteLine(tagMessage.Temperature); Debug.WriteLine(tagMessage.Humidity); Debug.WriteLine(tagMessage.Battery); var exist = _tags.FirstOrDefault(_ => _.MacAddress == tagMessage.MacAddress); if (exist != null) //Just save 1 dataset per scan { _tags.Remove(exist); } _tags.Add(tagMessage); } }
void Adapter_DeviceDisconnected(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { //DeviceDisconnectedEvent?.Invoke(sender,e); Debug.WriteLine("Device already disconnected"); }
void Adapter_DeviceConnected(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { Debug.WriteLine("Device already connected"); }
void Adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { DeviceList.Add(e.Device); }
private void Adapter_DeviceDisconnected(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { Debug.WriteLine($"Bluetooth device disconnected: {e.Device.Name}"); }
private void Adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { Toast toast = Toast.MakeText(this, "Device Found" + e.Device.Id.ToString(), ToastLength.Long); toast.Show(); }
private void Adaptador_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { var msg = string.Format("Device found: {0}", e.Device.Name); Toast.MakeText(this, msg, ToastLength.Long).Show(); }
private void _adapter_DeviceDiscovered(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { _adapter_DeviceDiscovered(e.Device); }
private void Adapter_DeviceConnected(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { SetBleConnected(); }
private async void _adapter_DeviceAdvertised(object sender, Plugin.BLE.Abstractions.EventArgs.DeviceEventArgs e) { if (e?.Device == null) { BpLogger.Debug("Null BLE advertisement received: skipping"); return; } string advertName = e.Device.GetPropValue <string>("BluetoothDevice.Name"); var advertGUIDs = new List <Guid>(); advertGUIDs.Add(e.Device.Id); var btAddr = e.Device.GetPropValue <string>("BluetoothDevice.Address"); BpLogger.Trace($"Got BLE Advertisement for device: {advertName} / {btAddr}"); if (_seenAddresses.Contains(btAddr)) { BpLogger.Trace($"Ignoring advertisement for already connecting device: {btAddr}"); return; } _seenAddresses.Add(btAddr); BpLogger.Trace("BLE device found: " + advertName); // We always need a name to match against. if (String.IsNullOrEmpty(advertName)) { return; } // todo Add advertGUIDs back in. Not sure that ever really gets used though. var deviceCriteria = new BluetoothLEProtocolConfiguration(advertName); var deviceFactory = DeviceConfigurationManager.Manager.Find(deviceCriteria); // If we don't have a protocol to match the device, we can't do anything with it. if (deviceFactory == null || !(deviceFactory.Config is BluetoothLEProtocolConfiguration bleConfig)) { BpLogger.Debug($"No usable device factory available for {advertName}."); return; } // If a device is turned on after scanning has started, windows seems to lose the device // handle the first couple of times it tries to deal with the advertisement. Just log the // error and hope it reconnects on a later retry. IButtplugDeviceImpl bleDevice = null; IButtplugDevice btDevice = null; try { await _adapter.ConnectToDeviceAsync(e.Device); bleDevice = await XamarinBluetoothDeviceInterface.Create(LogManager, bleConfig, e.Device).ConfigureAwait(false); btDevice = await deviceFactory.CreateDevice(LogManager, bleDevice).ConfigureAwait(false); InvokeDeviceAdded(new DeviceAddedEventArgs(btDevice)); } catch (Exception ex) { if (btDevice != null) { btDevice.Disconnect(); } else { bleDevice?.Disconnect(); } BpLogger.Error( $"Cannot connect to device {advertName} {btAddr}: {ex.Message}"); } }