You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
The text was updated successfully, but these errors were encountered:
@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
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
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 callingsetNotifiable
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:
Test Device:
iPad (6th generation) 15.3.1
Development Device:
Mac M1 Pro
The text was updated successfully, but these errors were encountered: