title: Windows UWP connect to BLE device after discovery
body: <p>I'm using <code>BluetoothLEAdvertisementWatcher</code> to find nearby BLE devices and it's working well. After finding them I want to connect and read/write data via GATT. But I can't figure out how to use the API after getting the <code>BluetoothLEAdvertisement</code> (<a href="https://msdn.microsoft.com/de-de/library/windows/apps/windows.devices.bluetooth.genericattributeprofile" rel="noreferrer">https://msdn.microsoft.com/de-de/library/windows/apps/windows.devices.bluetooth.genericattributeprofile</a>).</p>
  
  <pre><code>public class Adapter
  {
      private readonly BluetoothLEAdvertisementWatcher _bleWatcher = new BluetoothLEAdvertisementWatcher();
  
      public Adapter()
      {
          _bleWatcher.Received += BleWatcherOnReceived;
      }
  
      private void BleWatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
      {       
          // how to connect?
          // I know, it's the wrong place to to this, but this is just an example
      }
  
      public void StartScanningForDevices(Guid[] serviceUuids)
      {
          _blewatcher.advertisementfilter.advertisement.serviceuuids.clear();
          foreach (var uuid in serviceuuids)
          {
              _blewatcher.advertisementfilter.advertisement.serviceuuids.add(uuid);
          }
          _blewatcher.start();
      }
  }
  </code></pre>
  
  <p>I've found Samples that are using <code>DeviceInformation.FindAllAsync</code> instead of <code>BluetoothLEAdvertisementWatcher</code> but these are not working / finding any device.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After digging around some time, I found the following way. But unfortunately, the pairing fails. The device is just an Arduino with a BLE shield. I can definitely connect with Android and iOS. So it must be possible with UWP somehow. :/</p>
  
  <pre><code>private void BleWatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
  {       
      var dev = await BluetoothLEDevice.FromBluetoothAddressAsync(args.BluetoothAddress);
      // dev.DeviceInformation.Pairing.CanPair is true
      // dpr.Status is Failed
      DevicePairingResult dpr = await dev.DeviceInformation.Pairing.PairAsync(DevicePairingProtectionLevel.None);
      var service = await GattDeviceService.FromIdAsync(dev.DeviceInformation.Id);
  }
  </code></pre>
  
  <p><strong>UPDATE #2</strong></p>
  
  <p>I'm now able to discover and pair (unstable, but ok for now), but </p>
  
  <pre><code>var service = await GattDeviceService.FromIdAsync(args.Id);
  </code></pre>
  
  <p>throws the following Exception</p>
  
  <blockquote>
    <p>System.IO.FileNotFoundException: 
    The system cannot find the file specified. (Exception from HRESULT: 0x80070002)</p>
  </blockquote>
  
  <p>I have no clue why.</p>