none
Bluetooth LE (BLE) - can't access characteristics RRS feed

  • Question

  • I have a redbearlab bluetooth LE  (BLE) device that I'm trying to access via a Windows 8.1 App.  I am able to get the device Service but when I try to get the characteristics, I'm failing.  I finally added some code to cycle though all the short codes 0-ffff and I do get 3 characteristics but not the ones I want.  Also, I'm not able to write to a "writable" characteristic (2A00).

    Maybe it is a problem with my Package.appxmanifest?  I've added a lot to it trying to get it to work but no luck. 


    public async Task EnumerateDevicesAsync(Rect invokerRect) { ////////////////////// //DeviceInformation serviceInfo = (DeviceInformation) //DeviceInformation.FindAllAsync(); this.State = BluetoothConnectionState.Connecting; //try //{ // // Initialize the target Bluetooth RFCOMM device service // connectService = RfcommDeviceService.FromIdAsync(serviceInfo.Id); var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.GenericAccess)); if (devices.Count == 0) return; //Connect to the service var device = devices[0]; var service = await GattDeviceService.FromIdAsync(device.Id); // Trying a few ways to get the characteristics but they all return 0 items var RBL_DEVICE_RX_UUID_list = service.GetCharacteristics(new Guid("00001802-0000-1000-8000-00805f9b34fb")); //var RBL_DEVICE_RX_UUID = RBL_DEVICE_RX_UUID_list[0]; var RBL_DEVICE_TX_UUID = service.GetCharacteristics(new Guid("00001801-0000-1000-8000-00805f9b34fb")); var RBL_DEVICE_RX_UUID_list2 = service.GetCharacteristics(new Guid("713D0002-503E-4C75-BA94-3148F18D941E")); //var RBL_DEVICE_RX_UUID = RBL_DEVICE_RX_UUID_list[0]; var RBL_DEVICE_TX_UUID2 = service.GetCharacteristics(new Guid("713D0003-503E-4C75-BA94-3148F18D941E")); // I tried looking at the short ID and get 3 services at 2A00, 2A01, and 2A04

    //2A00 is the device name and the characteristic says it is writable. However, if I write to it, I get an accessed denied exception

    for (ushort i = 0; i < 0xffff; ++i) { var characteristics = service.GetCharacteristics(GattCharacteristic.ConvertShortIdToUuid(i)); //var characteristic = service.GetCharacteristics(GattCharacteristic.ConvertShortIdToUuid(i))[0]; if(characteristics.Count>0) { var characteristic = characteristics[0]; var value= await characteristic.ReadValueAsync(); //var result = await characteristics.ReadValueAsync(BluetoothCacheMode.Uncached); if (value.Status == GattCommunicationStatus.Success) { byte[] data = new byte[value.Value.Length]; DataReader.FromBuffer(value.Value).ReadBytes(data); string str = data.ToString(); str.CompareTo("G"); if (characteristic.CharacteristicProperties.Equals(GattCharacteristicProperties.WriteWithoutResponse)) { byte[] send = { 67 }; // 'C var buff = send.AsBuffer(); await characteristic.WriteValueAsync(buff, GattWriteOption.WriteWithoutResponse); } } } }

    Here is my Manifest.  I've added a few things at the end to get the characteristics to work.  See the bluetooth.genericAttributeProfile part at the end.

    <?xml version="1.0" encoding="utf-8"?>
    <Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest">
      <Identity Name="1b2dd8e5-77f9-4ae9-8683-c4e46a492b0f" Publisher="CN=Michael" Version="1.0.0.0" />
      <Properties>
        <DisplayName>BluetoothCommunicationSampleController</DisplayName>
        <PublisherDisplayName>Michael</PublisherDisplayName>
        <Logo>Assets\StoreLogo.png</Logo>
      </Properties>
      <Prerequisites>
        <OSMinVersion>6.3.0</OSMinVersion>
        <OSMaxVersionTested>6.3.0</OSMaxVersionTested>
      </Prerequisites>
      <Resources>
        <Resource Language="x-generate" />
      </Resources>
      <Applications>
        <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="BluetoothCommunicationSampleController.App">
          <m2:VisualElements DisplayName="BluetoothCommunicationSampleController" Square150x150Logo="Assets\Logo.png" Square30x30Logo="Assets\SmallLogo.png" Description="BluetoothCommunicationSampleController" ForegroundText="light" BackgroundColor="#464646">
            <m2:SplashScreen Image="Assets\SplashScreen.png" />
            <m2:ApplicationView MinWidth="width320" />
          </m2:VisualElements>
        </Application>
      </Applications>
      <Capabilities>
        <m2:DeviceCapability Name="bluetooth.rfcomm">
          <m2:Device Id="any">
            <m2:Function Type="name:serialPort" />
          </m2:Device>
        </m2:DeviceCapability>
        <m2:DeviceCapability Name="bluetooth.genericAttributeProfile">
          <m2:Device Id="any">
            <m2:Function Type="serviceId:713d0000-503e-4c75-ba94-3148f18d941e"/>
            <m2:Function Type="serviceId:00001800-0000-1000-8000-00805f9b34fb"/>
            <m2:Function Type="serviceId:00001801-0000-1000-8000-00805f9b34fb"/>
            <m2:Function Type="serviceId:0000180A-0000-1000-8000-00805f9b34fb"/>
    <!--        6e3bb679-4372-40c8-9eaa-4509df260cd8
            <m2:Function Type="serviceId:713D0001"/>
            <m2:Function Type="serviceId:713D0002"/>
            <m2:Function Type="serviceId:713D0003"/>
            <m2:Function Type="serviceId:713D0004"/>
            <m2:Function Type="serviceId:713D0005"/>
           -->
            
          <m2:Function Type="serviceId:713D0001-503E-4C75-BA94-3148F18D941E"/>
            <m2:Function Type="serviceId:713D0002-503E-4C75-BA94-3148F18D941E"/>
            <m2:Function Type="serviceId:713D0003-503E-4C75-BA94-3148F18D941E"/>
            <m2:Function Type="serviceId:713D0004-503E-4C75-BA94-3148F18D941E"/>
            <m2:Function Type="serviceId:00002a00-0000-1000-8000-00805f9b34fb"/>
            <m2:Function Type="serviceId:00002a01-0000-1000-8000-00805f9b34fb"/>
            <m2:Function Type="serviceId:00002a02-0000-1000-8000-00805f9b34fb"/>
            <m2:Function Type="serviceId:00002a03-0000-1000-8000-00805f9b34fb"/>
            <m2:Function Type="serviceId:00002a04-0000-1000-8000-00805f9b34fb"/>
            <m2:Function Type="serviceId:00002a05-0000-1000-8000-00805f9b34fb"/>
    
            <m2:Function Type="serviceId:00002902-0000-1000-8000-00805f9b34fb"/>
            <m2:Function Type="serviceId:00002A25-0000-1000-8000-00805f9b34fb"/>
          </m2:Device>
        </m2:DeviceCapability>
      </Capabilities>
    </Package>


    Saturday, August 30, 2014 3:11 AM