Comments (6)
Tried this again after I learned some lessons about async ... another version of the code (device is a BluetoothDevice). Based on logs from flutter_blue, all the characteristics are getting read, no errors being caught, it looks like one or more Futures just don't return.
Could also be my code or a Dart issue!
Future.wait(_charValMap.keys.map(powerDevice.scanResult.device.readCharacteristic))
.then((List<List<int>> listList) {
print('Inside Future.wait, listList has ${listList.length} elements');
})
.catchError((e) {
print('error $e');
});
from flutter_blue.
I'll have some time to investigate this next week, thanks for reporting!
from flutter_blue.
Future.wait
will fire off the functions in quick succession.
Both iOS and Android only support one readCharacteristic attempt at a time, or in other words, you must wait for the readCharacteristic to return before calling it again.
Dart makes this easy with async functions like so:
readAll() async {
final value1 = await device.readCharacteristic(char1);
final value2 = await device.readCharacteristic(char2);
// do something with value1 and value2
}
Here, the await
keyword will wait for readCharacteristic to return before moving onto the next line of code.
If you wanted similar functionality to your function you could do something like:
Future<List> readAll() async {
final value1 = await device.readCharacteristic(char1);
final value2 = await device.readCharacteristic(char2);
return [value1, value2];
}
readAll().then((values) => print('${values.length} read.'));
from flutter_blue.
re: one attempt at a time ... I was not aware of the limitation in iOS / Android, can you point me at a reference? (It might actually be a BLE limitation -- I write embedded BLE firmware also and this might be a spec thing ...)
re: firing off in quick succession, yes indeed. But based on what I'm seeing logged, it looks like flutter_blue is actually executing all the reads successfully ... the log looks just like it does on my successful approach using await in a loop ... I wonder if the right solution here is (assuming you can detect multiple overlapping read attempts) is to error out, or to actually allow it to work (sequentially) by returning futures for all requests when they complete ... right now it almost "succeeds silently" ...
Here's my current approach, given that flutter_blue gives me lists of characteristics: looping through a list (this just does the bluetooth value to internal model mapping on one characteristic at the moment):
for (BluetoothCharacteristic char in _charValMap.keys.toList()) {
tmpIntList = await powerDevice.scanResult.device.readCharacteristic(char);
_charValMap[char] = tmpIntList;
print('processed _charValMap item: ${char.uuid} ${tmpIntList.toString()}');
// Process/save values here ...
}
from flutter_blue.
I am unable to replicate this issue @jack4git
Closing this for now, please reopen if you are still experiencing this in the latest version.
from flutter_blue.
There are three services out of which the third one should be used to read and write characteristic.The first two are generic and the third one is custom service using which it will work. Try this :
_scanResult.device.discoverServices().then((services){
services[2].characteristics[0].read();
});
from flutter_blue.
Related Issues (20)
- There is a problem compiling the library with Flutter 3.7.12 with Gradle 8 HOT 4
- Flutter_blue_plus scan not working when the device screen is off
- Initiating ble channel upon collision detection to trigger alarm HOT 1
- Race condition between Connect timeout and a successful connection leaving active connection stranded HOT 2
- MissingPluginException on device.connect() HOT 2
- upgrade your rxdart library to latest, its conflicting with other libraries because of older version HOT 1
- Gamepanel gp isn't null buy I still get a null pointer exception when I call speak()
- 🚨🚨🚨 [Public Service Announcement] flutter_blue_plus is the successor to this library 🚨🚨🚨
- Command execution not working?
- C:\Users\ABS\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_blue_plus-1.15.2\android\src\main\java\com\boskokg\flutter_blue_plus\FlutterBluePlusPlugin.java uses or overrides a deprecated API.
- Help to resolve this error HOT 3
- ITMS-90863: Apple silicon Macs support issue HOT 3
- App crash when try readValue on android but on windows work fine
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨 HOT 1
- reading return value from
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨
- Could not resolve all files for configuration ':lib-transparency-api:protobufToolsLocator_protoc'. HOT 1
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨
- Execution failed for task ':flutter_blue:generateDebugProto'. HOT 1
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨
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.