Closed DHT-Xavier closed 3 weeks ago
please open a PR
thanks
but i don't think your fix is correct
to be clear, fbp has never been tested with secondaryServiceUuid
so you should test everything and open a pr to fix everything
to be clear, fbp has never been tested with secondaryServiceUuid
so you should test everything and open a pr to fix everything
I am not familiar with BLE and android native. I did mention that it was a temporary code modification in order to subscribe to the characteristic. The characteristic properties still shows notify: false, indicate: false, etc. I was able to tell what I think is a problem base on the hint in the PlatformException.
try
secondaryServiceUuid: secondaryServiceUuid
A new PlatformException returned:
PlatformException(setNotifyValue, secondaryService not found '181b', null, null)
Seems this is returning from flutter_blue_plus-1.32.11\android\src\main\java\com\lib\flutter_blue_plus\FlutterBluePlusPlugin.java
line 1614
On the same file, line 1612, should serviceId
change to secondaryServiceId
?
I forked this project and tried to apply the fix. Those changes seems work as excepted in my use case.
Please feel free to take a look and verify the change => Comparing changes.
Sorry for closing. pressed the wrong button by accident.
hi, thanks for following up! sorry for the slow response.
I'll merge them!
this change does not look correct:
if (s.serviceUuid == (secondaryServiceUuid ?? serviceUuid))
I think we would check both serviceUuid
&& secondaryServiceUuid
match.
I think it should be this
// get known service
BmBluetoothService? get _bmsvc {
if (FlutterBluePlus._knownServices[remoteId] != null) {
for (var s in FlutterBluePlus._knownServices[remoteId]!.services) {
if (s.serviceUuid == serviceUuid) {
if (secondaryServiceUuid != null) {
// search includedServices (i.e. secondary services)
for (var s2 in s.includedServices) {
if (s2.serviceUuid == secondaryServiceUuid) {
return s2;
}
}
} else {
return s;
}
}
}
}
return null;
}
/// get known characteristic
BmBluetoothCharacteristic? get _bmchr {
if (_bmsvc != null) {
for (var c in _bmsvc!.characteristics) {
if (c.characteristicUuid == uuid) {
return c;
}
}
}
return null;
}
for reference, a 'discoverServices' result with secondary services would look like this:
[
{
"uuid": "180D",
"type": "primary",
"description": "Heart Rate Service",
"characteristics": [
{
"uuid": "2A37",
"description": "Heart Rate Measurement"
},
{
"uuid": "2A38",
"description": "Body Sensor Location"
}
]
},
{
"uuid": "180F",
"type": "primary",
"description": "Battery Service",
"characteristics": [
{
"uuid": "2A19",
"description": "Battery Level"
}
]
},
{
"uuid": "1823",
"type": "secondary",
"description": "Heart Rate Sensor Configuration",
"characteristics": [
{
"uuid": "2A52",
"description": "Heart Rate Control Point"
}
],
"associatedPrimaryService": "180D"
}
]
you can see, the secondaryService has an associatedPrimaryService.
associatedPrimaryService seems like a good easy way to represent them.
But annoyingly it looks like iOS, Android, and FlutterBlue instead sometimes use includedServices to represent them, and other times use a primary + secondary uuid pair.
the code is inconsistent, and therefore harder to understand.
I'd rather we refactor the code to use associatedPrimaryService everywhere possible.
added in 1.34.0
please open new issues if you find bugs.
Requirements
Have you checked this problem on the example app?
Yes
FlutterBluePlus Version
1.32.11
Flutter Version
3.22.3
What OS?
Android
OS Version
13
Bluetooth Module
Build-in BLE module on Samsung Galaxy Tab A9+
What is your problem?
I am using FBP to connect a weight scale using BLE. The scale has 2 service (
0x181D
for weight and0x181B
for body composition). Each of them should contain 2 characteristics forREAD
andINDICATE
with a Descriptor for CCC.Characteristics
0x2A9E
,0x2A9D
under service0x181D
are working fine However, Characteristics0x2A9B
,0x2A9C
under service0x181B
(whichisPrimary: false
) are not able toREAD
orINDICATE
A
PlatformException
return while tried tosetNotifyValue(true)
on0x2A9C
Seems while I am trying to do anything on the characteristic under service which is not primary service, it tried to sending command to it's serviceUuid but not the secondaryServiceUuid. To temporary fix this issue, I change the code in
flutter_blue_plus-1.32.11\lib\src\bluetooth_characteristic.dart
line248
from
to
So that I can temporary
setNotifyValue
to the characteristicHere are some details of the
isPrimary: false
service and characteristic under the service.0x181B
BluetoothService:0x2A9C
BluetoothCharacteristic:This is what FBP example app discover:
This is a simple demo flutter app using FBP to list all services and characteristics and properties:
This is the services discover result using nRF Connect app on the same device connecting the same ble device:
Logs