chipweinberger / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, macOS
Other
791 stars 479 forks source link

[Bug]: Service UUIDs no longer found in advertismentData #672

Closed LipJ01 closed 1 year ago

LipJ01 commented 1 year ago

Requirements

Have you checked this problem on the example app?

No

FlutterBluePlus Version

1.27.1-1.28.7

Flutter Version

3.14.0

What OS?

iOS

OS Version

17.1.1

Bluetooth Module

Nordic nRF52833

What is your problem?

The following code snippet no longer works the same. Prior to 1.27.1 This will find the serviceUUID that my ble device is advertising. Post 1.27.0 I always have empty serviceUUID field in advertismentData.

FlutterBluePlus.scanResults.listen((results) {
    for (ScanResult r in results) {
        print('BLE: ${r.device.platformName} GATT table: ${r.advertisementData}');
    }
}

Logs

Previously:
BLE: MicroNode_123456_v6.5.13 GATT table: AdvertisementData{localName: MicroNode_123456_v6.5.13, txPowerLevel: null, connectable: true, manufacturerData: {}, serviceData: {}, serviceUuids: [8D53DC1D-1DB7-4CD3-868B-8A527460AA84]}

Now:
BLE: MicroNode_123456_v6.5.13 GATT table: AdvertisementData{localName: MicroNode_123456_v6.5.13, txPowerLevel: null, connectable: true, manufacturerData: {}, serviceData: {}, serviceUuids: []}
chipweinberger commented 1 year ago

try master branch

chipweinberger commented 1 year ago

fixed in 1.28.8

LipJ01 commented 1 year ago

I've just tested. This is NOT fixed. Please reopen issue and perhaps slow down the releases a tad.

sprimm98 commented 1 year ago

Hi! This problem also exists in version 1.29.11 (Flutter 3.16.2 on Android 11). Please reopen this thread.

chipweinberger commented 1 year ago

@sprimm98 open a new issue.

also perhaps you can debug the issue, and open a PR. maybe the problem is here.

        // Service UUIDs
        List<String> serviceUuidsB = new ArrayList<String>();
        if(serviceUuids != null) {
            for (ParcelUuid s : serviceUuids) {
                serviceUuidsB.add(uuidStr(s.getUuid()));
            }
        }
sprimm98 commented 1 year ago

Thanks for replying @chipweinberger. For now, I'll set continuousUpdates back to true for scanning as this seems to solve the problem. I don't think there is an issue with that snippet above, maybe it's related to the Bluetooth module.

chipweinberger commented 1 year ago

please can you try to debug it? ie why do you need to set continuousUpdates to get a response?

this seems to be a common problem

chipweinberger commented 1 year ago

its related to this bug: https://github.com/boskokg/flutter_blue_plus/issues/710#issuecomment-1837140039

can you add these logs

                log(logLevel.DEBUG, remoteId + " advHex:" + advHex); 

                // filter duplicates
                if (((boolean) mScanFilters.get("continuous_updates")) == false) {
                    boolean isDuplicate = mAdvSeen.containsKey(remoteId) && mAdvSeen.get(remoteId).equals(advHex);
                    mAdvSeen.put(remoteId, advHex); // remember
                    if (isDuplicate) {
                        log(logLevel.DEBUG, "filtered duplicate. " + remoteId);
                        return;
                    }
                }

                    // filter keywords
                    String name = scanRecord != null ? scanRecord.getDeviceName() : "";
                    List<String> keywords = (List<String>) mScanFilters.get("with_keywords");
                    if (filterKeywords(keywords, name) == false) {
                        log(logLevel.DEBUG, "filtered keyword " + remoteId);
                        return;
                    }

                    // filter divisor
                    if (((boolean) mScanFilters.get("continuous_updates")) != false) {
                        int count = scanCountIncrement(remoteId);   
                        int divisor = (int) mScanFilters.get("continuous_divisor");
                        if ((count % divisor) != 0) {
                            log(logLevel.DEBUG, "filtered divisor " + remoteId);
                            return;
                        }
                    }
sprimm98 commented 1 year ago

These logs worked as expected, showing remoteId and advHex. So I went back to startScan and assumed this was caused by CALLBACK_TYPE_FIRST_MATCH. However, you have already addressed this in the latest release. Thanks.