mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
Enhance Bluetooth scanning and notification handling for web platform
This commit is contained in:
parent
c23a1da430
commit
5f4333398e
1 changed files with 24 additions and 12 deletions
|
|
@ -738,7 +738,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||
});
|
||||
|
||||
await FlutterBluePlus.startScan(
|
||||
withKeywords: ["MeshCore-", "Whisper-"],
|
||||
withKeywords: ["MeshCore-", "Whisper-", "Wismesh-", "WisCore-"],
|
||||
webOptionalServices: [Guid(MeshCoreUuids.service)],
|
||||
timeout: timeout,
|
||||
androidScanMode: AndroidScanMode.lowLatency,
|
||||
|
|
@ -836,18 +836,30 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||
throw Exception("MeshCore characteristics not found");
|
||||
}
|
||||
|
||||
// Retry setNotifyValue with increasing delays
|
||||
bool notifySet = false;
|
||||
for (int attempt = 0; attempt < 3 && !notifySet; attempt++) {
|
||||
try {
|
||||
if (attempt > 0) {
|
||||
await Future.delayed(Duration(milliseconds: 500 * attempt));
|
||||
if (PlatformInfo.isWeb) {
|
||||
debugPrint('Starting setNotifyValue(true)');
|
||||
debugPrint('Web: Calling setNotifyValue(true) without awaiting');
|
||||
unawaited(() async {
|
||||
try {
|
||||
await _txCharacteristic!.setNotifyValue(true);
|
||||
} catch (error) {
|
||||
debugPrint('Web setNotifyValue error (ignoring): $error');
|
||||
}
|
||||
}());
|
||||
debugPrint('setNotifyValue(true) configuration completed');
|
||||
} else {
|
||||
bool notifySet = false;
|
||||
for (int attempt = 0; attempt < 3 && !notifySet; attempt++) {
|
||||
try {
|
||||
if (attempt > 0) {
|
||||
await Future.delayed(Duration(milliseconds: 500 * attempt));
|
||||
}
|
||||
await _txCharacteristic!.setNotifyValue(true);
|
||||
notifySet = true;
|
||||
} catch (e) {
|
||||
debugPrint('setNotifyValue attempt ${attempt + 1}/3 failed: $e');
|
||||
if (attempt == 2) rethrow;
|
||||
}
|
||||
await _txCharacteristic!.setNotifyValue(true);
|
||||
notifySet = true;
|
||||
} catch (e) {
|
||||
debugPrint('setNotifyValue attempt ${attempt + 1}/3 failed: $e');
|
||||
if (attempt == 2) rethrow;
|
||||
}
|
||||
}
|
||||
_notifySubscription = _txCharacteristic!.onValueReceived.listen(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue