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

iOS setNotifiable custom service/char #157

Open
dlewis2017 opened this issue Jul 25, 2023 · 3 comments
Open

iOS setNotifiable custom service/char #157

dlewis2017 opened this issue Jul 25, 2023 · 3 comments

Comments

@dlewis2017
Copy link

dlewis2017 commented Jul 25, 2023

Hello,

I can't seem to subscribe/setNotifiable custom service/characteristics

I'm trying to subscribe to a custom service's characteristic but getting a nil error when calling setNotifiable
I see in the Swift code the id has to have been in the services array or be formatted for more general characteristics (like battery) but that array is showing up as empty. Where do the service Ids and characteristic Ids get set before calling setNotifiable and is this needed?

Swift error location:

  public func getCharacteristic(_ characteristic: String, of service: String) -> CBCharacteristic {
    let s = self.services?.first {
      $0.uuid.uuidStr == service || "0000\($0.uuid.uuidStr)-\(GSS_SUFFIX)" == service
    }
    let c = s?.characteristics?.first {
      $0.uuid.uuidStr == characteristic || "0000\($0.uuid.uuidStr)-\(GSS_SUFFIX)" == characteristic
    }
    return c!
  }

  public func setNotifiable(_ bleInputProperty: String, for characteristic: String, of service: String) {
    setNotifyValue(bleInputProperty != "disabled", for: getCharacteristic(characteristic, of: service))
  }

Test Device:
iPad (6th generation) 15.3.1

Development Device:
Mac M1 Pro

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.5, on macOS 13.2.1 22D68 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.80.1)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

@nick-craffey
Copy link

Also getting this error on iOS.

@dlewis2017
Copy link
Author

@nick-craffey I haven't gotten around to testing it yet or dive into documentation but I was using another library quick_blue_plus and I had to "discover services" for the services to actually be populated within a Bluetooth object, then I could perform writes/reads/setNotifiable. So this library might need the same thing. Although last time I checked, that call in this library isn't awaited so that could prove challenging. The other library's discover services call is awaited

@dlewis2017
Copy link
Author

So my above hypothesis was correct. You first have to discoverServices (for me - after connecting) and then you're able to successfully set setNotifiable.

Some updated documentation would be helpful to know that. Maybe it's common BLE knoweldge.

Another recommended update would be to make this functions discover all services/characteristics and have it be async. I had to wait for when the service/characteristic I needed popped up in the handler setServiceHandler and then act on it, otherwise it might not be registered in the Peripheral in time.

This specific issue can be closed when the author of the repo sees it, but I would recommend one or both of the above as an enhancement to this repo

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

No branches or pull requests

2 participants