deviceplug / btleplug

Rust Cross-Platform Host-Side Bluetooth LE Access Library
Other
774 stars 145 forks source link

Wrong peripheral name on macOS #334

Open Massimiliano-solutiontech opened 1 year ago

Massimiliano-solutiontech commented 1 year ago

Describe the bug properties.local_name doesn't have the correct name because macOS caches the names

Expected behavior Have the correct advertised name

Actual behavior Returning the cached named

Additional context Below the Swift code working on iOS, iPadOS, but I didn't tested it on macOS

https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/1518937-centralmanager

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String: Any], rssi RSSI: NSNumber) {
    guard let name = advertisementData["kCBAdvDataLocalName"] as? String else { return }
}

I have experience with Swift and iOS development, if you need help to implement that I'll be happy to do so

Massimiliano-solutiontech commented 11 months ago

Any news on that?

gmallios commented 5 months ago

I've implemented this and checked if the advertisement data contains the LocalName but no luck. Connecting to the device upon discovery seems to solve this issue.

Apple forums and GH link regarding this bug:
https://developer.apple.com/forums/thread/654654 https://github.com/ChrisMarshallNY/TestCBIssue

yuyoyuppe commented 2 months ago

Having the same issue, the fix by @Massimiliano-solutiontech has helped. In my case kCBAdvDataLocalName contained a far more descriptive name.

Specifically, my treadmill is displayed as "LifeSpan-TM-2000" when scanning on Windows with btleplug/nrfconnect on Android. However, on macOS 14.5 it's displayed as "ESP32".

I'm not sure what's the most appropriate fix would be, since exposing a new field in a Peripheral for all platforms would likely be an overkill, but I guess we can merge names on macOS If both fields are present?

qdot commented 2 months ago

I think I'll be fine merging them, but I'll have to try them in my own library and see what it does.

yuyoyuppe commented 2 months ago

@qdot rebased against dev.