none
BluetoothLEDevice (Adafruit Bluefruit Feather) always reports Unreachable RRS feed

  • Question

  • I've written some fairly simple UWP code to try and access a BluetoothLEDevice, and while it works on an SH-HC-08 plugin module for a Teensy, it fails every time when I try it against a Bluefruit Feather from Adafruit. Adafruit is less than useful in that they don't support Windows Phone, and show no interest in helping other than assuming it's the BLE implementation in Microsoft's stack that's at fault. Before I return this Adafruit board to Amazon for a refund, I thought I'd ask here and see if anyone has some advice on how to make this work?
    Here's the important part of the code in question, but I'll happily provide the whole thing if it'll help. On Windows Phone 10, this code always signals "Unreachable" in the "stat" value.

            private async void SendButton_Click(object sender, RoutedEventArgs e)
            {
                foreach (var sz in devicesList.Where(x=>x.IsChecked))
                {
                    BluetoothLEDevice dev = await BluetoothLEDevice.FromIdAsync(sz.Id);
                    if (dev == null) continue;
                    // These numbers are for the SH-HC-08 device
                    //var gattSvc1 = dev.GetGattService(new Guid("0000ffe0-0000-1000-8000-00805f9b34fb"));
                    //var gattChar1 = gattSvc1.GetCharacteristics(new Guid("0000ffe1-0000-1000-8000-00805f9b34fb"));
                    // These numbers are for the AdaFruit Feather Bluefruit device, using the BLEUART sketch.
                    if (gattSvc1 == null)
                        gattSvc1 = dev.GetGattService(new Guid("6e400001-b5a3-f393-e0a9-e50e24dcca9e"));
                    var gattChar1 = gattSvc1.GetCharacteristics(new Guid("6e400002-b5a3-f393-e0a9-e50e24dcca9e")).First();
                    byte[] ar1 = Encoding.ASCII.GetBytes(TextToSend.Text+"\n");
    
                    GattCommunicationStatus stat = await gattChar1.WriteValueAsync(ar1.AsBuffer(), GattWriteOption.WriteWithoutResponse);
    
                }
            }
    One piece of information - if I check the gattSvc1.Device.DeviceInformation values, it shows "IsEnabled" as false - don't know if this is relevant, or how to enable the device if it is relevant.


    Alun.


    • Edited by Alun Jones Friday, June 16, 2017 5:59 PM
    Friday, June 16, 2017 5:57 PM

Answers

  • A further piece of the puzzle... I hand edited the package.appxmanifest to contain this:

        <DeviceCapability Name="bluetooth.genericAttributeProfile">
          <Device Id="any">
            <Function Type="serviceId:6e400001-b5a3-f393-e0a9-e50e24dcca9e" />
            <Function Type="name:genericAccess" />
          </Device>
        </DeviceCapability>

    Once I did this, I managed to get a successful run - but it's unreliable - in Windows 10 (not Phone). Frequently, though, I get ObjectDisposedException on the GetCharacteristics call. I suspect the "name:genericAccess" line isn't useful here.
    Still not working at all on the Windows 10 Phone (Lumia 950)


    Alun.



    • Edited by Alun Jones Friday, June 16, 2017 7:23 PM
    • Marked as answer by Alun Jones Friday, June 16, 2017 9:34 PM
    Friday, June 16, 2017 6:57 PM

All replies

  • A further piece of the puzzle... I hand edited the package.appxmanifest to contain this:

        <DeviceCapability Name="bluetooth.genericAttributeProfile">
          <Device Id="any">
            <Function Type="serviceId:6e400001-b5a3-f393-e0a9-e50e24dcca9e" />
            <Function Type="name:genericAccess" />
          </Device>
        </DeviceCapability>

    Once I did this, I managed to get a successful run - but it's unreliable - in Windows 10 (not Phone). Frequently, though, I get ObjectDisposedException on the GetCharacteristics call. I suspect the "name:genericAccess" line isn't useful here.
    Still not working at all on the Windows 10 Phone (Lumia 950)


    Alun.



    • Edited by Alun Jones Friday, June 16, 2017 7:23 PM
    • Marked as answer by Alun Jones Friday, June 16, 2017 9:34 PM
    Friday, June 16, 2017 6:57 PM
  • ... and then, after removing the device from the phone's list of pairs, then re-pairing it to the phone, the code works again on the phone.

    There's still some reliability issues brought about by not handling the case where the device has yet to connect, and I wonder what will cause the connection to fail again, but for now this seems to have made life work. Any advice on good samples for BLE implementations for the phone would be very much appreciated.

    Seems like my issues are related to https://social.msdn.microsoft.com/Forums/windowsapps/en-US/69c3d5b0-f445-44c7-985c-b1b755247dc2/bluetooth-low-energy-cant-write-after-reconnect?forum=wpdevelop#69c3d5b0-f445-44c7-985c-b1b755247dc2


    Alun.


    • Edited by Alun Jones Friday, June 16, 2017 9:35 PM
    Friday, June 16, 2017 9:34 PM