/// <summary> /// Method subscribed to a CBMCentralManager's OnDiscoveredPeripheral Event /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> private void OnDiscoveredPeripheral(Object sender, CBDiscoveredPeripheralEventArgs e) { var peripheral = e.Peripheral; // Get advertised data and convert to dict var serviceDataDict = (NSDictionary)e.AdvertisementData[CBAdvertisement.DataServiceDataKey]; // Get keys becase keys are NSobjects and are weird to decipher, if no keys then null var serviceDataKeys = serviceDataDict?.Keys; // If the previous ID matches or the peripheral has the desired content... if (TemperatureSensor.Instance.UUID == peripheral.Identifier.ToString() || (serviceDataKeys != null && serviceDataKeys.Length == 2 && serviceDataKeys[0].Description == Constants.HEALTH_THERMOMETER && serviceDataKeys[1].Description == Constants.BATTERY)) { // Extract data var temperature = serviceDataDict[serviceDataKeys[0]].Description; temperature = Regex.Replace(temperature, "[<>]", ""); var battery = serviceDataDict[serviceDataKeys[1]].Description; battery = Regex.Replace(battery, "[<>]", ""); // Stop the scan once found _centralManager.StopScan(); _SetActivePeripheral(peripheral, temperature); } }
private void DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs args) { if ((args as CBDiscoveredPeripheralEventArgs).RSSI.Int32Value > _rssiThreshold && (args as CBDiscoveredPeripheralEventArgs).RSSI.Int32Value < 0) { Console.WriteLine("Check UUID : " + (args as CBDiscoveredPeripheralEventArgs).AdvertisementData); var tempUUID = (args as CBDiscoveredPeripheralEventArgs).AdvertisementData .ValueForKey((NSString)"kCBAdvDataManufacturerData"); if (tempUUID != null) { string bufferUUID = tempUUID.ToString(); string identifierUUID = ExtractBeaconUUID(bufferUUID); if (identifierUUID.Length == 36) { List <BeaconSignalModel> signals = new List <BeaconSignalModel>(); signals.Add(new BeaconSignalModel { UUID = new Guid(identifierUUID), RSSI = (args as CBDiscoveredPeripheralEventArgs).RSSI.Int32Value }); _event.OnEventCall(new BeaconScanEventArgs { _signals = signals }); } } } }
private void DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs args) { var device = $"{args.Peripheral.Name} - {args.Peripheral.Identifier?.Description}"; Debug.WriteLine($"Discovered {device}"); this.DiscoveredDevice?.Invoke(sender, args.Peripheral); }
private void OnDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { var device = new BLEDevice(_managerWrapper, e.Peripheral); var rssi = e.RSSI.Int32Value; var advertisements = BLEAdvertisement.Parse(e.AdvertisementData); RaiseDeviceDiscovered(device, rssi, advertisements); }
private void HandleDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { System.Threading.Tasks.Task.Run(() => { Covi.Features.BluetoothTracing.TracingState.Instance.SetScanningState(true); GetPeripheralManager().HandleDiscoveredPeripheral(e); }).FireAndForget(); }
// This method is run everytime a peripheral is discovered public void DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs args) { // Invokes the DiscoveredDevice method in the ViewController.cs page if (args?.Peripheral?.Name != null) { Console.WriteLine(args.Peripheral.Name); } this.DiscoveredDevice?.Invoke(sender, args); }
public void HandleDiscoveredPeripheral(CBDiscoveredPeripheralEventArgs evnt) { var descriptor = evnt.Peripheral.ToDeviceDescriptor(); _manager.HandleDeviceDiscovered(descriptor, (d) => { _centralManager.ConnectPeripheral(evnt.Peripheral); }); }
void OnDeviceDiscovered(object sender, CBDiscoveredPeripheralEventArgs e) { Device d = new Device(); d.Peripheral = e.Peripheral; d.RSSI = e.RSSI?.Int32Value ?? -127; (contentView.DeviceTable.Source as DeviceTableSource).AddDevice(d); }
private void CentralManagerOnDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { discoveredDevices.Add(e.Peripheral); if (e.AdvertisementData.ContainsKey(CBAdvertisement.DataManufacturerDataKey)) { // For debugging var data = e.AdvertisementData[CBAdvertisement.DataManufacturerDataKey]; } Console.WriteLine(e.AdvertisementData); }
private void _manager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { System.Diagnostics.Debug.WriteLine(e.Peripheral.Identifier); _foundDevices.Add(e.Peripheral); #if __IOS__ if (controller != null) { controller.AddTextField((t) => { t.Text = e.Peripheral.Name; }); } #endif }
private void OnDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs args) { var name = args.AdvertisementData[CBAdvertisement.DataLocalNameKey].ToString(); Debug.WriteLine("Discovered peripheral: " + name + " With UUID: " + args.Peripheral.Identifier); if (_onDiscoveredPeripheral != null) { _onDiscoveredPeripheral(args.Peripheral, name); } }
private void DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { var deviceId = Device.DeviceIdentifierToGuid(e.Peripheral.Identifier); if (DiscoveredDevices.All(x => x.Id != deviceId)) { var device = new Device(e.Peripheral); DiscoveredDevices.Add(device); DeviceDiscovered(this, new DeviceDiscoveredEventArgs(device)); } }
static void OnManagerDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { if (peripheral != null) { return; } Console.WriteLine("Discovered peripheral"); DeviceDiscovered?.Invoke(null, e); }
private void _centralManager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { if (e != null && e.Peripheral != null && e.Peripheral.Identifier != null) { this._devices.Add(new Device { Address = e.Peripheral.Identifier.AsString(), Name = e.Peripheral.Name, NativeDevice = e.Peripheral }); } }
private void Bluetooth_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { if (!string.IsNullOrEmpty(e.Peripheral.Name) && !_devices.Contains(e.Peripheral)) { System.Diagnostics.Debug.WriteLine(e.Peripheral.Name + " " + e.Peripheral.Identifier.ToString()); UIDevice.CurrentDevice.BeginInvokeOnMainThread(() => { _devices.Add(e.Peripheral); OnReloadData(); }); } }
public void DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs args) { var device = $"{args.Peripheral.Name} - {args.Peripheral.Identifier?.Description}"; Debug.WriteLine($"Discovered {device}"); if (!string.IsNullOrEmpty(args.Peripheral.Name)) { Discovered?.Invoke(new RomeRemoteSystem(args.Peripheral) { DisplayName = args.Peripheral.Name, Id = args.Peripheral.Identifier.ToString() }); } }
// This method writes every unique DiscoveredDevice's name to the console private void DiscoveredDevice(object sender, CBDiscoveredPeripheralEventArgs args) { if (args?.Peripheral?.Name != null) { var btn = UIButton.FromType(UIButtonType.System); btn.Frame = new CGRect(10, h, View.Bounds.Width - 20, 40); btn.SetTitle($"Connect to {args.Peripheral.Name}", UIControlState.Normal); btn.TouchUpInside += (sendee, e) => { this.bluetoothService.ConnectTo(args.Peripheral); }; View.AddSubview(btn); h = h + 40; } }
void DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { var peripheral = e.Peripheral; var device = new BleDevice() { Uuid = peripheral.Identifier.ToString(), Name = peripheral.Name, State = "Connecting...", }; devices.Add(device.Uuid, device); manager.ConnectPeripheral(peripheral, new PeripheralConnectionOptions()); OnSomethingHappened(); }
/// <summary> /// Gets the discovered devices. /// </summary> /// <value>The discovered devices.</value> //public IList<IDevice> DiscoveredDevices { // get { return _devices.ToList(); } //} /// <summary> /// Gets the connected devices. /// </summary> /// <value>The connected devices.</value> //public IList<IDevice> ConnectedDevices { // get { // return _devices.Where(x => x.State == DeviceState.Connected).ToList(); // } //} #endregion #region CBCentralManager delegate methods private void DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { var deviceId = Device.DeviceIdentifierToGuid(e.Peripheral.Identifier); if (_discoveringDevices.All(x => x.Id != deviceId)) { var device = new Device(e.Peripheral, e.RSSI); _discoveringDevices.Add(device); device.AdvertismentData = ProcessData(e.AdvertisementData); device.AdvertisedServiceUuids = ProcessUuids(e.AdvertisementData); if (_devices.All(x => x.Id != device.Id)) { _devices.Add(device); } DeviceDiscovered(this, new DeviceDiscoveredEventArgs(device)); } }
private void Bluetooth_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { /*foreach (var item in e.AdvertisementData) * { * if (item.Key.ToString() == CBAdvertisement.DataLocalNameKey) * { * System.Diagnostics.Debug.WriteLine($"{item.Key} {item.Value}"); * } * }*/ //if (!string.IsNullOrEmpty(peripheral.Name)) //{ System.Diagnostics.Debug.WriteLine(e.Peripheral.Name + " " + e.Peripheral.Identifier.ToString()); if (!string.IsNullOrEmpty(e.Peripheral.Name) && !_devices.Contains(e.Peripheral)) { UIDevice.CurrentDevice.BeginInvokeOnMainThread(() => { _devices.Add(e.Peripheral); OnReloadData(); }); } }
void OnDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { BLEPeripheral peripheral = null; foreach (BLEPeripheral blep in discoveredPeripherals) { if (blep.UUID.StringValue.Equals(e.Peripheral.ToString())) { peripheral = blep; break; } } if (peripheral == null) { peripheral = new BLEPeripheral(e.Peripheral); discoveredPeripherals.Add(peripheral); } EventHandler <BLEDiscoveredPeripheralEventArgs> handler = DiscoveredPeripheral; if (handler != null) { BLEDiscoveredPeripheralEventArgs args = new BLEDiscoveredPeripheralEventArgs(); args.AdvertisementData = new List <KeyValuePair <string, string> > (); args.Peripheral = peripheral; args.RSSI = e.RSSI.Int32Value; foreach (KeyValuePair <NSObject, NSObject> kvp in e.AdvertisementData) { args.AdvertisementData.Add(new KeyValuePair <string, string> (kvp.Key.ToString(), kvp.Value.ToString())); } handler(this, args); } }
void DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs discoveredPeripheralEventArgs) { var peripheral = discoveredPeripheralEventArgs.Peripheral; if (peripheral == null || peripheral.Name == null) { return; } var name = peripheral.Name; DiscoveredPeripheralEventHandler?.Invoke(this, new DiscoveredPeripheralEventArgs(name)); if (name == nameOfPeripheralToConnectTo) { // This is weird behaviour... If we only connect to the first // peripheral of this name, we seem to be connected after a // while and can send the pin and read the properties except // for the secret key. // If we also try to connect to the subsequently discovered // peripheral of the same name, the connection will block until // you press the timer button on the thermostat. Then we can // send the pin code and get the secret key. if (firstConnect && discoveredPeripherals.Count == 0) { Console.Error.WriteLine("Push the timer button on the thermostat"); } else { Console.Error.WriteLine("Found thermostat. Connecting."); central.DiscoveredPeripheral -= DiscoveredPeripheral; } discoveredPeripherals.Add(peripheral); central.ConnectPeripheral(peripheral); } }
private void OnDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) => _wes.RaiseEvent(nameof(DiscoveredPeripheral), sender, e);
/// <summary> /// Handles the DiscoveredPeripheral event of the manager control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="CBDiscoveredPeripheralEventArgs"/> instance containing the event data.</param> void manager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { System.Diagnostics.Debug.WriteLine(e); }
/* private static void _manager_RetrievedConnectedPeripherals(object sender, CBPeripheralsEventArgs e) { foreach(CBPeripheral p in e.Peripherals ) { _devices.Add(new DeviceInformation(p)); } retrievedHandle.Set(); }*/ private static void _manager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { foreach(KeyValuePair<NSObject,NSObject> kvp in e.AdvertisementData) { System.Diagnostics.Debug.WriteLine(kvp.Key.ToString() + " " + kvp.Value.ToString()); } //e.Peripheral. System.Diagnostics.Debug.WriteLine(e.RSSI.ToString()); _devices.Add(new DeviceInformation(e.Peripheral, e.AdvertisementData["kCBAdvDataLocalName"].ToString())); }
void manager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { System.Diagnostics.Debug.WriteLine(e); }
private void CentralManager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { }
private void ManagerOnDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { _devices.Add(new BluetoothDevice(e.Peripheral.Name, e.Peripheral.Identifier.AsString())); }
private static void _manager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { throw new NotImplementedException(); }
/// <summary> /// Logs the peripheral details. /// </summary> /// <param name="message">Message.</param> /// <param name="e">E.</param> void LogPeripheralDetails(string message, CBDiscoveredPeripheralEventArgs e) { Console.WriteLine($"{message}: {e.Peripheral.Identifier} {e.Peripheral}"); Console.WriteLine($"data: {e.AdvertisementData}"); }