none
How to establish a connection from windows 8 PC to a Bluetooth low energy device? RRS feed

  • Question

  • Hi,

    I need to establish a connection to a remote Bluetooth low energy device from my windows 8 PC ( I have a Bluetooth USB Dongle to connect to the PC). I already know the BLE device's ID. Now I just have to make a connection and send some data to the device from PC.

    I searched this blog and perused through the Bluetooth LE samples given here " http://code.msdn.microsoft.com/windowshardware/Bluetooth-Generic-4f4ea968/view/Discussions" but did not find the method I want. I should be able to connect to the device by providing the device ID by myself. But the samples have  a method that enumerates the available devices and then connects to the required device. I am working on Visual C++ (Win32 application). 

    Any sample would be very really helpful. 

    Thanks in advance for your response.



    • Edited by phanitk Thursday, February 21, 2013 10:58 AM
    Thursday, February 21, 2013 10:43 AM

Answers

All replies

  • Hi,

    The Windows 8 Bluetooth GATT apis requires that the device be paired using the built-in UI and does not allow application to connect to an arbitrary Bluetooth LE device.  Please refer to the Bluetooth Low Energy documentation for more details.
    http://msdn.microsoft.com/en-us/library/windows/hardware/hh450825(v=vs.85).aspx

    This whitepaper might also be useful:
    http://msdn.microsoft.com/en-us/library/windows/hardware/hh833780.aspx

    Thanks
    Alain Michaud [MSFT]


    Thursday, February 21, 2013 3:17 PM
  • Hi Alain,

    Thank you for your help!!

    Friday, February 22, 2013 4:14 AM
  • Hi Alain,

    As you suggested, I was able to pair with Bluetooth Low energy device using built UI and installation functions available from                  http://msdn.microsoft.com/en-us/library/windows/hardware/ff549791(v=vs.85).aspx  

    I am able to get a handle to the device and use it in the GATT APIs ( get services and get characteristics) and the buffers obtained were correct.

    http://msdn.microsoft.com/en-us/library/windows/hardware/hh450825(v=vs.85).aspx

    Everything went well till I tried to send a value to the device using set characteristic value. It is giving an error as ACCESS DENIED where as the same device handle worked well with  earlier functions.

    When I tried to give Service Buffer from get services functionas a handle ( as it asked for a service handle) I am getting an error as INVALID_HANDLE.

    If you need further information or the code I have written let me know..

    Please help with this..

    Thanks in advance

    phanitk


    • Edited by phanitk Thursday, February 28, 2013 2:07 PM
    Thursday, February 28, 2013 2:06 PM
  • Hi,

    I have the same problem here:

    First, I connect to a BT LE device using the Windows 8  UI. => OK

    Then I run my own program, that:

    * Enumerates the devices, which implement the bluetooth LE interface class. OK => my program finds one device.

    * Enumerates the interfaces for this device. OK => my program finds one interface. 

    * Then it gets the device interface path and does a CreateFile to get the device hande. OK => I get a valid path & handle.

    * It uses the handle to call the BluetoothGATTGetServices & characteristics. So far all OK => I can enumerate the services & characteristics.

    From the moment I try to read a value, register for an event, ... I get an ACCESS DENIED error. (I guess in general I get this error as soon as I make an API  call which requires communication with the BT LE device over the air??).

    The msdn API documentation makes distinction between a device and a service handle. How to get a service handle?

    Furthermore, what parameters do I have to give to CreateFile regarding permissions/sharing/security ?

    Any idea what could be wrong?

    Thx,

    Dirk

    Friday, March 8, 2013 3:00 PM
  • Hi,

    I think you might have already found a solution

    If not...

    How it worked for me is, I tried enumerating the devices using Service Id, instead of Bluetooth LE interface class GUID..

    I think you should be able to get service ID from device manager...

    Thursday, March 21, 2013 8:01 AM
  • Hi,

    Nice to hear that it is working for you!

    For me it is still not clear where to get the "service ID"... 

    And are you using this service ID as a parameter to "SetupDIGetClassDevs" ?

    Are you prepared to share some pieces of your code?

    Thx,

    Dirk


    • Proposed as answer by powerboy_zds Wednesday, April 2, 2014 7:35 AM
    • Unproposed as answer by powerboy_zds Wednesday, April 2, 2014 7:35 AM
    Thursday, March 21, 2013 12:10 PM
  • Hi,

    Download GUID explorer and check for UID of the device service from which you want to read a value...

    Yes, you have to give this as a parameter to SetupDIGetClassDevs and also SetupDIEnumDeviceInterfaces..

    Friday, March 22, 2013 4:07 AM
  • Hello,

    Is there a way for me to create my own application that can discover Bluetooth LE devices and has its own custom pairing sequence?

    Part of my BLE device's pairing sequence requires the Windows 8 side to input the passkey displayed on the device. Windows 8 skips this part and continues with adding the device to its list of paired devices. Resulting in pairing failure for the device's side.

    Wednesday, March 27, 2013 7:49 AM
  • Hi, 

    I have the same proble and I am trying to implement your solution but I have problems trying to open the resulting devicepath. 

    my code is 

    HANDLE TICC2540SimpleKeysServiceContent::getServiceHandle(){
    	
    // char DeviceName[255] = "";
    // char DevicePath[500] = "";
     HANDLE hOut = INVALID_HANDLE_VALUE;
     HRESULT hr = E_FAIL;
     CHECK_HR(hr, "get service handle");
    				
     HDEVINFO hDevInfo = SetupDiGetClassDevs(&SERVICE_TICC2540SimpleKeysService, NULL, NULL, DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);
      CHECK_HR(hr, "post setupdigetclassdevs");
    
     SP_DEVICE_INTERFACE_DATA deviceInfoData;
     deviceInfoData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA);
    // ULONG nGuessCount = MAXLONG;
    // for(ULONG iDevIndex=0; iDevIndex {
     ULONG iDevIndex = 0;
     CHECK_HR(hr, "pre if");
     while(iDevIndex < 10 ){
    	 if(SetupDiEnumDeviceInterfaces(hDevInfo, 0, &SERVICE_TICC2540SimpleKeysService, iDevIndex, &deviceInfoData))
    	 {
    		CHECK_HR(hr, "dentro if");
    
    		DWORD cbRequired = 0;
    
    		SetupDiGetDeviceInterfaceDetail(hDevInfo,
    										&deviceInfoData,
                                            0,
                                            0,
                                            &cbRequired,
                                            0);
    		CHECK_HR(hr, "Required %d ", cbRequired);
    
            if (ERROR_INSUFFICIENT_BUFFER == GetLastError())
             {
              PSP_DEVICE_INTERFACE_DETAIL_DATA pdidd =
                (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LPTR,
                                                             cbRequired);
              CHECK_HR(hr, "post local alloc ");
    
              if (pdidd)
               {
                pdidd->cbSize = sizeof(*pdidd);
                if (SetupDiGetDeviceInterfaceDetail(hDevInfo,
    												&deviceInfoData,
    												pdidd,
                                                    cbRequired,
                                                    &cbRequired,
                                                    0))
                 {
    				 CHECK_HR(hr, "post get device path %ls", pdidd->DevicePath);
    
    				 hOut= 
                          CreateFile(pdidd->DevicePath,
                                     GENERIC_READ | GENERIC_WRITE,
                                     FILE_SHARE_READ | FILE_SHARE_WRITE,
                                     NULL,
                                     OPEN_EXISTING,
                                     FILE_ATTRIBUTE_NORMAL,
                                     NULL);
    				 CHECK_HR(hr, "post open path ");
    
    			}
       		  LocalFree(pdidd);
    		  }
    
    		}	 
     
    	}
    	 else if(GetLastError() == ERROR_NO_MORE_ITEMS) //No more items
    	 {
    			 CHECK_HR(hr, "else if");
    
    	 //m_status.Format("ERROR_NO_MORE_ITEMS");
    	 break;
    	 }
    	 iDevIndex++;
     }
     SetupDiDestroyDeviceInfoList(hDevInfo);
         CHECK_HR(hr, "post setup di");
    
     return hOut; 
    }

    Any comment would be helpful... 

    thanks

    Jorge

    Wednesday, April 3, 2013 6:12 AM
  • By the way, the 2 device path retrieved are: 

    \\?\bthledevice#{0000ffe0-0000-1000-8000-00805f9b34fb}_dev_vid&01000d_pid&0000_rev&0110_78c5e56c0883#9&15ce670f&c&0045#{0000ffe0-0000-1000-8000-00805f9b34fb}\bthlegatt_ticc2540simplekeysservice 
    and
    \\?\bthledevice#{0000ffe0-0000-1000-8000-00805f9b34fb}_dev_vid&01000d_pid&0000_rev&0110_78c5e56c0883#9&15ce670f&c&0045#{0000ffe0-0000-1000-8000-00805f9b34fb}

    regards

    jorge

    Wednesday, April 3, 2013 2:35 PM
  • Hi,

    I have to write a BLE-Application for university. Can you send me a code example how you established the connection?

    Thank you very much!

    Friday, April 12, 2013 11:57 AM
  • Hi,

    Windows 8's IO capabilities is set to DisplayYesNo.  The device should respect Io Capability to pairing sequence as defined in the Bluetooth Core specification.

    In recognition that this problem exists in several device implementation, especially the TI CC2540 based solution, Windows 8.1 has changed its IO capabilities to KeyboardDisplay which addresses this problem.

    For others in this thread above which seems to have problems opening up the service handle to do Get/Set value operations, this is most likely the same problem.

    So you have a few options to proceed:

    1. Get the latest TI FW for the CC2540 from TI.
    2. Update to Windows 8.1

    Thanks 

    Tuesday, April 15, 2014 5:39 PM
  • Hi

    Suggesting to play with gatttool first. It will help a lot. :

    I went to Ubuntu:

    installed latest bluze-5.

    hcitool lescan

    -> got mac address aa.bb.cc.dd.ee.ff of the BLE device in question

    gatttool -b aa.bb.cc.dd.ee.ff -I
    connect
    primary

    -> got all primary serices uuids.

    Then in Windows 8 I (after pairing, or just connect)  enumerated and created file for each of the uuid's until succeeded.

    bregards

    Giora

    Wednesday, August 19, 2015 10:28 AM
  • Hi,

    I want to know if this still applies to updated APIs for BLE?

    Best regards, Daniel

    Wednesday, October 5, 2016 9:21 AM