コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
        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
                        });
                    }
                }
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 private void HandleDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e)
 {
     System.Threading.Tasks.Task.Run(() =>
     {
         Covi.Features.BluetoothTracing.TracingState.Instance.SetScanningState(true);
         GetPeripheralManager().HandleDiscoveredPeripheral(e);
     }).FireAndForget();
 }
コード例 #6
0
ファイル: Bluetooth.cs プロジェクト: EtienneThompson/Sphero
 // 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);
 }
コード例 #7
0
        public void HandleDiscoveredPeripheral(CBDiscoveredPeripheralEventArgs evnt)
        {
            var descriptor = evnt.Peripheral.ToDeviceDescriptor();

            _manager.HandleDeviceDiscovered(descriptor, (d) =>
            {
                _centralManager.ConnectPeripheral(evnt.Peripheral);
            });
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: BluetoothIOS.cs プロジェクト: DbNero16/PruebaBT1
 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);
 }
コード例 #10
0
        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
        }
コード例 #11
0
ファイル: BluetoothScanner.cs プロジェクト: sbondini/BleChat
        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);
            }
        }
コード例 #12
0
        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));
            }
        }
コード例 #13
0
        static void OnManagerDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e)
        {
            if (peripheral != null)
            {
                return;
            }

            Console.WriteLine("Discovered peripheral");

            DeviceDiscovered?.Invoke(null, e);
        }
コード例 #14
0
 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
         });
     }
 }
コード例 #15
0
        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();
                });
            }
        }
コード例 #16
0
        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()
                });
            }
        }
コード例 #17
0
        // 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;
            }
        }
コード例 #18
0
        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();
        }
コード例 #19
0
        /// <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));
            }
        }
コード例 #20
0
        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();
                });
            }
        }
コード例 #21
0
        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);
            }
        }
コード例 #22
0
ファイル: MacOsBluetooth.cs プロジェクト: trocken2/Eco2
        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);
            }
        }
コード例 #23
0
 private void OnDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e)
 => _wes.RaiseEvent(nameof(DiscoveredPeripheral), sender, e);
コード例 #24
0
 /// <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);
 }
コード例 #25
0
       /* 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()));
        }
コード例 #26
0
 void manager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e)
 {
     System.Diagnostics.Debug.WriteLine(e);
 }
コード例 #27
0
 private void CentralManager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e)
 {
 }
コード例 #28
0
 private void ManagerOnDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e)
 {
     _devices.Add(new BluetoothDevice(e.Peripheral.Name, e.Peripheral.Identifier.AsString()));
 }
コード例 #29
0
 private static void _manager_DiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e)
 {
     throw new NotImplementedException();
 }
コード例 #30
0
		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));
			}
		}
コード例 #31
0
 /// <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}");
 }