Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paired device not being detected by call to Adapter.GetSystemConnectedOrPairedDevices #754

Open
TiisangMguni opened this issue Oct 12, 2023 · 3 comments

Comments

@TiisangMguni
Copy link

Hi, i am running the Maui sample (BLE.Client.Maui) on Android, I have a Bluetooth to serial device (HC06 Serial Bluetooth Brick) already paired with the phone on which i am running the sample app. The Bluetooth to serial device is connected to an Arduino device that continuously writes string data to the Arduino serial port.

The issue i am having is that the device (which shows in my paired devices under the name itead) is never returned by the call to
Adapter.GetSystemConnectedOrPairedDevices();. I can however connect to the device using other android apps from the google play store and read the data that it sends continuously.

Expected behavior

Expected a list with all paired devices

Actual behavior

The call only returns my paired Airpods

@smsissuechecker
Copy link

Hi @TiisangMguni,

I'm the friendly issue checker.
It seems like (75.00 %) you haven't used our issue template 😢 I think it is very frustrating for the repository owners, if you ignore them.

If you think it's fine to make an exception, just ignore this message.
But if you think it was a mistake to delete the template, please close the issue and create a new one.

Thanks!

@JuLights
Copy link

image

same problem, GetSystemConnectedOrPairedDevices() doesn't return anything, but I can see it(ESP32test) in android.bluetooth.BluetoothAdapter.BondedDevices.

@Auto72
Copy link

Auto72 commented Jan 18, 2024

I want to summarize the behavior of the Adapter.GetSystemConnectedOrPairedDevices() method with the BLE.Plugin ver. 3.1.0-beta.

var pdList = Adapter.GetSystemConnectedOrPairedDevices();
foreach(var pd in pdList) 
{
    Debug.WriteLine($"Name: {pd.Name} | Id: {pd.Id} | IsConnectable: {pd.IsConnectable} |");
}

On Android it works form me, I get the list of paired BLE devices.

On Windows doesn't work form me, what it works form me is the following:

    public override IReadOnlyList<IDevice> GetSystemConnectedOrPairedDevices(Guid[] services = null)
    {
        string pairedSelector = BluetoothLEDevice.GetDeviceSelectorFromPairingState(true);
        DeviceInformationCollection pairedDevices = DeviceInformation.FindAllAsync(pairedSelector).GetAwaiter().GetResult();
        List<IDevice> devlist = ConnectedDevices.ToList();
        List<Guid> ids = ConnectedDevices.Select(d => d.Id).ToList();
        foreach (var dev in pairedDevices)
        {
            Guid id = dev.Id.ToBleDeviceGuidFromId();
            ulong bleaddress = id.ToBleAddress();
            if (!ids.Contains(id))
            {
                var bluetoothLeDevice = BluetoothLEDevice.FromBluetoothAddressAsync(bleaddress).AsTask().Result;
                if (bluetoothLeDevice != null)
                {
                    var device = new Device(this, bluetoothLeDevice, 0, id);
                    devlist.Add(device);
                    ids.Add(id);
                    Trace.Message("GetSystemConnectedOrPairedDevices: {0}: {1}", dev.Id, dev.Name);
                }
                else
                {
                    Trace.Message("GetSystemConnectedOrPairedDevices: {0}: {1}, BluetoothLEDevice == null", dev.Id, dev.Name);
                }
            }
        }
        return devlist;
    }

NOTE: we need to use BluetoothLEDevice, instead of the current BluetoothDevice.

On iOS I get the following error when I try to call the method .GetSystemConnectedOrPairedDevices()

Value cannot be null. (Parameter 'serviceUUIDs')

    public override IReadOnlyList<IDevice> GetSystemConnectedOrPairedDevices(Guid[] services = null)
    {
        // NOTE: to avoid the null error, instead of using 'null' here, we need to use 'new CBUUID[1]'
        CBUUID[] serviceUuids = null;
        if (services != null)
        {
            serviceUuids = services.Select(guid => CBUUID.FromString(guid.ToString())).ToArray();
        }

        var nativeDevices = _centralManager.RetrieveConnectedPeripherals(serviceUuids);

        return nativeDevices.Select(d => new Device(this, d, _bleCentralManagerDelegate)).Cast<IDevice>().ToList();
    }

Anyway, even if I fix the problem in iOS that way, it doesn't return my paired BLE device, that I can see listed in 'My Devices' under the Bluetooth Settings.

I need help in iOS, in order to get my paired BLE device listed by the method .GetSystemConnectedOrPairedDevices()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants