title: Bluetooth Low Energy API Windows 8
body: <p>I need to write a Desktop application for Windows 8, that can communicate with Bluetooth Low Energy devices. After my Research I think this is only possible for Windows apps but not for a Desktop application because there are no APIs. Is there a way to use the APIs for the Windows apps in a Desktop application?</p>
  
  <p>Thanks</p>
  
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using Windows.Devices.Bluetooth.GenericAttributeProfile;
  using Windows.Devices.Enumeration;
  
  namespace WinRTNutzungVS2013
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
              try
              {
                  Initialize().GetAwaiter();
              }
              catch (Exception e)
              {
                  MessageBox.Show("Fehler");
              }
          }
  
          double convertTemperatureData(byte[] temperatureData)
          {
              UInt32 mantissa = ((UInt32)temperatureData[3] &lt;&lt; 16 | ((UInt32)temperatureData[2] &lt;&lt; 8) | ((UInt32)temperatureData[1]));
  
              Int32 exponent = (Int32)temperatureData[4];
  
              return mantissa * Math.Pow(10.0, exponent);
          }
  
          private async Task Initialize()
          {
              var themometerServices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.HealthThermometer), null);
              GattDeviceService firstThermometerService = await GattDeviceService.FromIdAsync(themometerServices[0].Id);
              tbServices.Text = "Using service: " + themometerServices[0].Name;
              GattCharacteristic thermometerCharacteristic = firstThermometerService.GetCharacteristics(GattCharacteristicUuids.TemperatureMeasurement)[0];
              thermometerCharacteristic.ValueChanged += temperatureMeasurementChanged;
              await thermometerCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);
          }
  
          void temperatureMeasurementChanged(GattCharacteristic sender, GattValueChangedEventArgs eventArgs)
          {
              byte[] temperatureData = new byte[eventArgs.CharacteristicValue.Length];
              Windows.Storage.Streams.DataReader.FromBuffer(eventArgs.CharacteristicValue).ReadBytes(temperatureData);
              var temperatureValue = convertTemperatureData(temperatureData);
              tbTemperature.Text = temperatureValue.ToString();
          }
      }
  }
  </code></pre>