Closed max-h-silverman closed 7 months ago
FBP only allows a single transaction in progress at one time.
This is for best reliability on all android versions and phones.
this locking happens in dart code, in the writeCharacteristic function
you can try to remove this lock, or move the lock to native code so there is reduced latency
this will require careful coding tho.
if you manage it, please open a pr
however a bigger issue - why are you discovering services so much?
that will destroy performance
Ok thanks. I'm using a third party package written for the Phomemo printer and the "sendData" function doesn't accept the characteristic as a parameter. I was able to modify the package locally to send the previously discovered write characteristic but it didn't change the overall time to complete the print.
Which part of the writeCharacteristic function is performing the lock?
Appreciate the quick response.
you need to not discover services after every write. that is your problem
Sorry what I was trying to say in the last note is that's what I tried but didn't see any performance increase. Below are the first few logs from that attempt. You can see the large time gap between "[FBP] onMethodCall: writeCharacteristic" and "[FBP] onCharacteristicWrite:" with no discovery happening after the initial one.
2024-05-02 10:49:41.732 32655-32655 [FBP-Android] com.flutterflow.mycofile D [FBP] onMethodCall: discoverServices 2024-05-02 10:49:41.732 32655-32655 BluetoothGatt com.flutterflow.mycofile D discoverServices() - device: 04:7F:0E:AC:C9:0F 2024-05-02 10:49:41.741 32655-32694 BluetoothGatt com.flutterflow.mycofile D onSearchComplete() = Device=04:7F:0E:AC:C9:0F Status=0 2024-05-02 10:49:41.742 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] onServicesDiscovered: 2024-05-02 10:49:41.742 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] count: 7 2024-05-02 10:49:41.742 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] status: 0GATT_SUCCESS 2024-05-02 10:49:42.084 32655-32655 [FBP-Android] com.flutterflow.mycofile D [FBP] onMethodCall: writeCharacteristic 2024-05-02 10:49:42.170 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] onCharacteristicWrite: 2024-05-02 10:49:42.171 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] chr: 49535343-6daa-4d02-abf6-19569aca69fe 2024-05-02 10:49:42.171 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] status: GATT_SUCCESS (0) 2024-05-02 10:49:42.175 32655-32754 flutter com.flutterflow.mycofile I Data sent successfully 2024-05-02 10:49:42.178 32655-32655 [FBP-Android] com.flutterflow.mycofile D [FBP] onMethodCall: writeCharacteristic 2024-05-02 10:49:42.441 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] onCharacteristicWrite: 2024-05-02 10:49:42.442 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] chr: 49535343-6daa-4d02-abf6-19569aca69fe 2024-05-02 10:49:42.442 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] status: GATT_SUCCESS (0) 2024-05-02 10:49:42.450 32655-32754 flutter com.flutterflow.mycofile I Data sent successfully 2024-05-02 10:49:42.453 32655-32655 [FBP-Android] com.flutterflow.mycofile D [FBP] onMethodCall: writeCharacteristic 2024-05-02 10:49:42.710 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] onCharacteristicWrite: 2024-05-02 10:49:42.711 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] chr: 49535343-6daa-4d02-abf6-19569aca69fe 2024-05-02 10:49:42.711 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] status: GATT_SUCCESS (0) 2024-05-02 10:49:42.716 32655-32754 flutter com.flutterflow.mycofile I Data sent successfully 2024-05-02 10:49:42.719 32655-32655 [FBP-Android] com.flutterflow.mycofile D [FBP] onMethodCall: writeCharacteristic 2024-05-02 10:49:42.981 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] onCharacteristicWrite: 2024-05-02 10:49:42.981 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] chr: 49535343-6daa-4d02-abf6-19569aca69fe 2024-05-02 10:49:42.982 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] status: GATT_SUCCESS (0) 2024-05-02 10:49:42.988 32655-32754 flutter com.flutterflow.mycofile I Data sent successfully 2024-05-02 10:49:42.991 32655-32655 [FBP-Android] com.flutterflow.mycofile D [FBP] onMethodCall: writeCharacteristic 2024-05-02 10:49:43.251 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] onCharacteristicWrite: 2024-05-02 10:49:43.251 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] chr: 49535343-6daa-4d02-abf6-19569aca69fe 2024-05-02 10:49:43.251 32655-32694 [FBP-Android] com.flutterflow.mycofile D [FBP] status: GATT_SUCCESS (0) 2024-05-02 10:49:43.256 32655-32754 flutter com.flutterflow.mycofile I Data sent successfully
you should also increase the android PHY speed
search FBP for the word PHY
Hey I wasn't able to identify the code responsible for this lock in writeCharacteristic. Can you point me to it? Thanks.
Requirements
Have you checked this problem on the example app?
No
FlutterBluePlus Version
1.32.4
Flutter Version
3.19.1
What OS?
Android
OS Version
Android 12
Bluetooth Module
Unsure (Phomemo M220 thermal printer)
What is your problem?
When sending image data to the printer using FBP the transmission takes about 3s (about 100ms per 256 bytes, roughly 30 packets). When sending the exact same data using the native Phomemo PrintMaster app, the transmission takes about 1/10th as long.
I've spent a few days digging into this to try and understand if my implementation isn't right, but it ultimately seems that the delay is happening in Flutter_Blue_plus.java. (logs below show a few of the calls.
I added detailed logging at one point to see more granular detail about where the time is being taken, and the relevant log capture is attached.
I retrieved the HCI Log from the device to confirm that the same amount of data is being transmitted by PrintMaster and by my app.
Appreciate any help you can offer.
Logs