Comments (25)
fixed: 66655d6
from flutter_blue_plus.
odd. at what point does the actual mtu change to a larger value?
Not sure, I'm going to go into the office on Tuesday and debug all of the BT traffic to figure it out.
from flutter_blue_plus.
Here's the request to our peripheral:
... and the response from our peripheral:
It looks like the value of 23 is coming from this plugin, not the peripheral.
Here's a discussion on the Apple forums about how to get the MTU size, and whether the onMtuChanged callback is actually called.
from flutter_blue_plus.
I added
[NSTimer scheduledTimerWithTimeInterval:.01
target:self
selector:@selector(logMtu:)
userInfo:@{@"peripheral":peripheral,}
repeats:YES];
to didConnectPeripheral
, with logMtu of
- (void)logMtu:(NSTimer *)timer {
CBPeripheral * peripheral = timer.userInfo[@"peripheral"];
NSLog( @"[FBP-iOS] logMtu %d", [self getMtu:peripheral]);
}
... and it looks like the value is ready in .06s for my phone and peripheral:
[FBP-iOS] didConnectPeripheral
[FBP-iOS] logMtu 23
[FBP-iOS] handleMethodCall: discoverServices
[FBP-iOS] logMtu 23
[FBP-iOS] logMtu 23
[FBP-iOS] logMtu 23
[FBP-iOS] logMtu 23
[FBP-iOS] logMtu 185
from flutter_blue_plus.
is "OnMtuChanged" ever seen in your logs?
I did change how the dart mtu code works. you can look at older versions. we used to actively get the mtu from the system, but now we just passively wait for OnMtuChanged. I find it odd if iOS does not report the mtu change.
from flutter_blue_plus.
something like this (see older code)
/// The current MTU size in bytes
Stream<int> get mtu {
// get initial value from our cache
int? initialValue = FlutterBluePlus._mtuValues[remoteId]?.mtu;
if (initialValue == null) {
// invoke getMtu from system
initialValue = invokeXXX
}
return FlutterBluePlus._methodStream.stream
.where((m) => m.method == "OnMtuChanged")
.map((m) => m.arguments)
.map((args) => BmMtuChangedResponse.fromMap(args))
.where((p) => p.remoteId == remoteId.str)
.map((p) => p.mtu)
.newStreamWithInitialValue(initialValue!);
}
from flutter_blue_plus.
yes this looks like a real bug in flutter blue plus.
i'm surprised no one else has noticed this.
in iOS, onMtuChanged is not exposed by iOS. We must actively ask for the mtu from the system.
I can fix this later next week.
from flutter_blue_plus.
Thank you for the fix, @chipweinberger!
A related question, is there any way to tell the difference between the default value and a reading from the peripheral? I'm planning on listening to the mtu stream until the value isn't 23, but this is awkward... I'd think the stream should only be populated with actual readings, and users of this plugin could implement their own default.
from flutter_blue_plus.
yes i was thinking about that issue as well.
before i release the next version i'll improve it
i think the solution is to change the order so that onMtuChanged is called before onConnectionStateChanged
then, after connection you can await device.mtu.first
and it will always be the correct value
another solution is similar to yours. remove default value and return first result after connection.
from flutter_blue_plus.
I tried a later patch (a5c2396), and I can see the new code is getting called, but I'm still only getting a single value of 23 from the mtu stream on my iPhone 6s.
... same results, one mtu value of 23, on a newer iPhone running iOS 17 beta.
from flutter_blue_plus.
odd. at what point does the actual mtu change to a larger value?
from flutter_blue_plus.
i'm surprised no one else has noticed this.
It looks like the error is relatively new (PlatformException(writeCharacteristic, data is longer than MTU allows. dataLen: 237 > maxDataLen: 182, null, null);
); I think this was failing silently before.
from flutter_blue_plus.
my main question is when will calling getMtu
return the correct value?
currently i call it in the onConnected handler. is that too soon?
from flutter_blue_plus.
perhaps you can try adding a separate thread that continually calls getMtu
and then we can figure out when it changes on the iOS platform
from flutter_blue_plus.
I think this was failing silently before.
on iOS, the platform will silently split your payload into multiple packets.
that is bad for performance, so i've made it an error, and provide a separate function (writeLarge
) in the README if you want auto splitting behavior.
from flutter_blue_plus.
it looks like the value is ready in .06s
Thanks for testing!!
This is tricky. How should we handle this?
perhaps we can
- add a timer that checks for mtu changes (just like you did), and caches the results
when the mtu changes:
- push to stream
when flutter blue plus ios code is initialized:
- create timer
thoughts?
from flutter_blue_plus.
I've pushed a fix to master: 5dc29c4
let me know if it works for you.
from flutter_blue_plus.
I took a quick look at the diff for this change, are you canceling the timer? I think once we get a non-23 value, we should no longer expect any changes, so there's a lot of unnecessary traffic (assuming that this MTU read gets passed along to the peripheral).
from flutter_blue_plus.
Is there a similar problem for large reads? We are getting some truncated data on the iPhone 6S; e.g. the length sent with the data says there should be 212 bytes, but we're now only receiving 182 bytes.
from flutter_blue_plus.
assuming that this MTU read gets passed along to the peripheral
no it does not get passed on. it is just reading a cached value.
canceling the timer could be nice but more complicated to support multiple devices. also a device may only support 23 MTU, so we'd need some timeout (maybe 30 seconds?). Overall kinda complicated to save what i think is a very small amount of perf. But i wish there was a simpler solution than a timer.
Is there a similar problem for large reads? We are getting some truncated data on the iPhone 6S; e.g. the length sent with the data says there should be 212 bytes, but we're now only receiving 182 bytes.
I would think this is a problem with your device firmware.
when you say now what do you mean? did it work on 1.4.0?
from flutter_blue_plus.
![Screenshot 2023-09-05 at 6 38 48 PM](https://private-user-images.githubusercontent.com/1863934/265865591-e3c2d0a4-8059-46e3-9667-93115043d9c7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4MjY5NDUsIm5iZiI6MTcyMzgyNjY0NSwicGF0aCI6Ii8xODYzOTM0LzI2NTg2NTU5MS1lM2MyZDBhNC04MDU5LTQ2ZTMtOTY2Ny05MzExNTA0M2Q5YzcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTZUMTY0NDA1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmNkYmM0ODk1YWE5YTBmNWJjYjdjZTBjOWZmMjc5ZjNjYmFiYzc4OTFhNjFiOWZmYmFmNGU3MDkyY2RkNTAxYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.ZPbOUJpemQY6nn-xT6VUxUYoSe6eKCDutqlKRUrKSK4)
![Screenshot 2023-09-05 at 6 42 15 PM](https://private-user-images.githubusercontent.com/1863934/265866034-60ec7ff3-1da6-4630-95b4-c5b35586d0f1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4MjY5NDUsIm5iZiI6MTcyMzgyNjY0NSwicGF0aCI6Ii8xODYzOTM0LzI2NTg2NjAzNC02MGVjN2ZmMy0xZGE2LTQ2MzAtOTViNC1jNWIzNTU4NmQwZjEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTZUMTY0NDA1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Yjc0MDhhZDM3MTUzNTc1M2UwOWMxY2VlYWRjMDgwYzI4NzFhNjg2ZDY2YjNhZmQ5YWE3MDVlOGJjZWM4ODZlYSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.LjNqAKE2Q-YZss_EYPtU87aGaXm1DwpsOCtOqa7Exgg)
It seems writeLarge
may not be work with subsequent reads if data > mtu.
I could remove these checks for writing larger than MTU. But we need to make sure all supported android versions operate this same way. i.e. support writing larger than MTU & autosplit
But perhaps there is some other way to fix this issue?
from flutter_blue_plus.
according to chatGPT, reading a characteristic on Android when data > MTU truncates to MTU length.
There seems to be no way to get the rest of the data.
If this is true, then iOS should be enforced to operate the same way.
from flutter_blue_plus.
in android, it seems the maximum write length is 512, hardcoded (note: GATT_MAX_ATTR_LEN == 512)
![Screenshot 2023-09-05 at 7 29 05 PM](https://private-user-images.githubusercontent.com/1863934/265873445-a4892b22-c6b1-422c-b144-222b70829fde.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4MjY5NDUsIm5iZiI6MTcyMzgyNjY0NSwicGF0aCI6Ii8xODYzOTM0LzI2NTg3MzQ0NS1hNDg5MmIyMi1jNmIxLTQyMmMtYjE0NC0yMjJiNzA4MjlmZGUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTZUMTY0NDA1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YWQ3NDUyYmEyZTg0MjZhOGQzYzJiM2UyNjQ0M2NjZTE5NzdiMjRlMDAyMzk1ODk1YjZhMWRkNTg0YmE5YzJkNCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.0nOC3j857MbSm8gv9xU67iJ73IfLVhO48frEmwfmfuA)
from flutter_blue_plus.
fixed in 1.14.13.
the length sent with the data says there should be 212 bytes, but we're now only receiving 182 bytes.
try using allowSplits
, added in 1.14.13. open a new issue if you still have problems.
from flutter_blue_plus.
in android, it seems the maximum write length is 512, hardcoded (note: GATT_MAX_ATTR_LEN == 512)
Different Android versions will support different values; I believe Android 14+ have a mtu of 517.
from flutter_blue_plus.
Related Issues (20)
- [Help]: The second time cannot be written HOT 3
- [Bug]: secondary services dont work HOT 6
- [Help]: Empty scan result on HiOS v14.0.0 HOT 5
- [Help]: Why can't my reading and listening receive any information HOT 2
- [Help]: onValueReceived stops receiving data if screen turned off or app moved in the background
- [Help]: Auto connect only works when scanning after disconnection HOT 1
- [Feature]: read/write/notify value as raw bytes HOT 1
- [Bug]: Certain Bluetooth devices crash with GATT_INSUFFICIENT_RESOURCES on Android because of iOS compatibility code HOT 6
- [Help]: Handling Android limiting 5 scans in 30 seconds HOT 3
- [Help]: Problems when using with "flutter_ble_peripheral" packge HOT 1
- Bluetooth permission
- [Help]: Delay when disconnect HOT 2
- [Help]: Bluetooth device shows up in iOS "Other Devices" but not through FlutterBluePlus HOT 1
- [Feature]: Refresh cache without connected HOT 1
- [Help]: Unused UUID on the BLE device causes error code 14 on IOS ONLY. HOT 2
- [Feature]: Is it possible to increase the minSdk Version HOT 2
- [Help]: Samsung mobile phone HOT 2
- [Help]: ble pairing request popup appears twice HOT 4
- Unable to obtain Bluetooth devices connected to the system HOT 2
- [Help]: BluetoothDevice.fromProto::platformName HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_blue_plus.