Shikhar Tandon
Shikhar Tandon

Reputation: 41

Displaying "Device Unreachable" after running BluetoothLE app code in Visual Studio.(UWP)

I am Trying to run BluetoothLE code from Universal Windows Sample-->https://github.com/Microsoft/Windows-universal-samples Initially the device gets paired successfully

But when i click the Connect button it shows error message "Device Unreachable" I put a breakpoint at the starting of this code snippet and the result varible was not equal to GattCommunicationStatus.Success.

GattDeviceServicesResult result = await bluetoothLeDevice.GetGattServicesAsync(BluetoothCacheMode.Uncached);
gatt = (int)result.Status;
if (result.Status == GattCommunicationStatus.Success)
{
    var services = result.Services;
    rootPage.NotifyUser(String.Format("Found {0} services", services.Count), NotifyType.StatusMessage);
    foreach (var service in services)
    {
        ServiceCollection.Add(new BluetoothLEAttributeDisplay(service));
    }
    ConnectButton.Visibility = Visibility.Collapsed;
    ServiceList.Visibility = Visibility.Visible;
}
else
{
    rootPage.NotifyUser("Device unreachable", NotifyType.ErrorMessage);
}

Please help Thanks

Upvotes: 1

Views: 3380

Answers (2)

Chris Cardus
Chris Cardus

Reputation: 21

I was struggling with exactly the same problem, but I think I've found the answer. From a post on the Microsoft Q&A website. I'm relatively inexperienced, so take my explanation with a pinch of salt, but this is my understanding of the problem:

It revolves around Bluetooth Low Energy (BLE) Privacy. To prevent the tracking of a user via the Bluetooth advertisements their smartphone is constantly emitting, the MAC address of the device is changed periodically; no more than every fifteen minutes. The randomised address is known as a Resolvable Random Private Address. For paired devices to be able to keep track of the device, a symmetric key called an Identity Resolving Key (IRK) is exchanged during pairing. This key can then be used to resolve the identity of the device from the random MAC addresses it is advertising.

Microsoft's implementation of BLE on Windows doesn't include all aspects of BLE Privacy. Specifically, it only supports Random Private Addresses while advertising. This means that, after you pair a device with a Windows PC, Windows doesn't randomise it's MAC address or provide the paired device with an Identity Resolving Key. Modern implementations of BLE, specifically on smartphones, seemingly do not allow connections with devices that don't implement Resolvable Random Private Addresses, such as Windows PCs. This could be because it is seen as suspicious behaviour.

Therefore, when using BLE to connect a Windows PC to another device, Android in my case, you can connect to the device and read the BLE services from the device while not paired. As soon as you pair the two devices however, the second device rejects the connection and the Windows device will always return "Device Unreachable" when trying to read the Gatt services.

Upvotes: 2

Breeze Liu - MSFT
Breeze Liu - MSFT

Reputation: 3808

This issue may be caused by your device or the Bluetooth environment, you can try to turn off your Bluetooth device then turn on it again on your devices to test it again. You can open and close the Bluetooth on your device Settings app => Devices => Bluetooth & other devices.

See the MSDN thread Problem with BluetoothLE code, GattCommunicationStatus.Success is not working

Upvotes: 0

Related Questions