From 3a1fcf8b1cccda2e485304a3d9e67ab5754af841 Mon Sep 17 00:00:00 2001 From: bardram Date: Sun, 26 Nov 2023 13:31:07 +0100 Subject: [PATCH] upgrade to flutter_blue_plus 1.29 API & published as 3.1.0 --- packages/movisens_flutter/CHANGELOG.md | 7 +++- packages/movisens_flutter/README.md | 32 +++++++++++++------ .../example/android/app/build.gradle | 2 +- .../android/app/src/main/AndroidManifest.xml | 26 +++++++++++++-- .../com/example/example/MainActivity.kt | 6 ---- .../movisens_flutter/lib/movisens_device.dart | 26 +++++++-------- packages/movisens_flutter/pubspec.yaml | 10 +++--- 7 files changed, 71 insertions(+), 38 deletions(-) delete mode 100644 packages/movisens_flutter/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt diff --git a/packages/movisens_flutter/CHANGELOG.md b/packages/movisens_flutter/CHANGELOG.md index a3ac20346..950accd5f 100644 --- a/packages/movisens_flutter/CHANGELOG.md +++ b/packages/movisens_flutter/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.1.0 + +- Upgrade to flutter version 3.2.0 +- Upgrade to `flutter_blue_plus: ^1.29.0` + ## 3.0.0 - Upgrade to flutter version 3.0.0 @@ -20,7 +25,7 @@ ## 1.0.0 -- Reimplentation of package to use direct bluetooth communication using `flutter_blue_plus` instead of Movisens libraries +- Re-implementation of package to use direct Bluetooth communication using `flutter_blue_plus` instead of Movisens libraries ## 0.2.0 diff --git a/packages/movisens_flutter/README.md b/packages/movisens_flutter/README.md index 95a5da0dc..921658337 100644 --- a/packages/movisens_flutter/README.md +++ b/packages/movisens_flutter/README.md @@ -6,26 +6,40 @@ A plugin for connecting and collecting data from a Movisens sensor. Works for bo ## Install -Add `movisens_flutter` as a dependency in `pubspec.yaml`. -For help on adding as a dependency, view the [documentation](https://flutter.io/using-packages/). +Add `movisens_flutter` as a dependency in `pubspec.yaml`. For help on adding as a dependency, view the [documentation](https://flutter.io/using-packages/). + +This plugin uses the [flutter_blue_plus](https://pub.dev/packages/flutter_blue_plus) plugin and apps using this plugin should follow the [setup guide for flutter_blue](https://pub.dev/packages/flutter_blue_plus#getting-started). ### Android Add the following to your `android/app/src/main/AndroidManifest.xml` : -```dart - - - +```xml + + + + + + + + + + + + + + ``` -Update the `android/app/build.gradle` to `minSdkVersion` at least 19 +Update the `android/app/build.gradle` to `minSdkVersion` at least 21. ```gradle android { defaultConfig { ... - minSdkVersion 19 + minSdkVersion 21 ... } } @@ -61,7 +75,7 @@ As illustrated below, each service has a 1 or more `MovisensBluetoothCharacteris ### Undocumented API -4 services and 9 characterisics are not documented in Movisens' documentation as they are part of the general Bluetooth GATT specifications but have been added to this plugin. +4 services and 9 characteristics are not documented in Movisens' documentation as they are part of the general Bluetooth GATT specifications but have been added to this plugin. Below is a list of their names and UUIDs. The battery service, heart rate service and user data service have been added to the movisens specific implementations for simplicity of the plugin API. - SERVICE: 0000180f-0000-1000-8000-00805f9b34fb // **_BATTERY SERVICE_** (added to the Battery Service) diff --git a/packages/movisens_flutter/example/android/app/build.gradle b/packages/movisens_flutter/example/android/app/build.gradle index 7f0f1a520..c9b0773bf 100644 --- a/packages/movisens_flutter/example/android/app/build.gradle +++ b/packages/movisens_flutter/example/android/app/build.gradle @@ -47,7 +47,7 @@ android { applicationId "com.example.example" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. - minSdkVersion 19 + minSdkVersion 21 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/packages/movisens_flutter/example/android/app/src/main/AndroidManifest.xml b/packages/movisens_flutter/example/android/app/src/main/AndroidManifest.xml index 7e2e8f33b..0c0219e3f 100644 --- a/packages/movisens_flutter/example/android/app/src/main/AndroidManifest.xml +++ b/packages/movisens_flutter/example/android/app/src/main/AndroidManifest.xml @@ -1,13 +1,33 @@ - + + + + + + + + + + + + + + + + + + - ? get state => _bluetoothDevice?.state; + Stream? get state => + _bluetoothDevice?.connectionState; /// Get the [AmbientService] if the device supports it. /// Is null if not supported / discovered on device. @@ -99,13 +100,11 @@ class MovisensDevice { /// Automatically discovers services on device and stores them. Future connect() async { _log.info("Connecting to movisens device using name: [$name]"); - FlutterBluePlus flutterBluePlus = FlutterBluePlus.instance; // Checking if already connected - skips the rest of connect if true // TODO: If already connected - can `device.connect()` be avoided? - List connectedDevices = - await flutterBluePlus.connectedDevices; + List connectedDevices = FlutterBluePlus.connectedDevices; for (BluetoothDevice device in connectedDevices) { - if (device.name == name) { + if (device.platformName == name) { await device.connect(); _bluetoothDevice = device; // Discover services @@ -116,9 +115,9 @@ class MovisensDevice { // (For android) Check if the device is bonded if (Platform.isAndroid) { - List bondedDevices = await flutterBluePlus.bondedDevices; + List bondedDevices = await FlutterBluePlus.bondedDevices; for (BluetoothDevice device in bondedDevices) { - if (device.name == name) { + if (device.platformName == name) { await device.connect(); _bluetoothDevice = device; // Discover services @@ -129,17 +128,18 @@ class MovisensDevice { } // Scan for devices - flutterBluePlus.startScan(timeout: const Duration(seconds: 10)); + FlutterBluePlus.startScan(timeout: const Duration(seconds: 10)); late StreamSubscription subscription; - subscription = flutterBluePlus.scanResults.listen((scanResults) async { + subscription = FlutterBluePlus.scanResults.listen((scanResults) async { // Select only 1 device to connect to ScanResult? scanResult = - (scanResults.any((element) => element.device.name == name)) - ? scanResults.firstWhere((element) => element.device.name == name) + (scanResults.any((element) => element.device.platformName == name)) + ? scanResults + .firstWhere((element) => element.device.platformName == name) : null; // connect, stop scanning and clean streams if (scanResult != null) { - await flutterBluePlus.stopScan(); + await FlutterBluePlus.stopScan(); await scanResult.device.connect(); _bluetoothDevice = scanResult.device; await _discoverAndSetup(); @@ -150,7 +150,7 @@ class MovisensDevice { // Discovers services on device and instantiates them Future _discoverAndSetup() async { - id = _bluetoothDevice!.id.id; + id = _bluetoothDevice!.remoteId.str; _log.info("Stored ID [$id] from Movisens device [$name]"); _log.info("Discovering services on Movisens device [$id]"); // Discover services diff --git a/packages/movisens_flutter/pubspec.yaml b/packages/movisens_flutter/pubspec.yaml index b9a566371..3398aff9b 100644 --- a/packages/movisens_flutter/pubspec.yaml +++ b/packages/movisens_flutter/pubspec.yaml @@ -1,17 +1,17 @@ name: movisens_flutter description: A Flutter plugin for Movisens devices, which connects to the device and listens for incoming data. -version: 3.0.0 +version: 3.1.0 homepage: https://github.com/cph-cachet/flutter-plugins/tree/master/packages/movisens_flutter environment: - sdk: ">=2.18.2 <4.0.0" - flutter: ">=3.0.0" - + sdk: ">=3.2.0 <4.0.0" + flutter: ">=3.6.0" + dependencies: flutter: sdk: flutter path_provider: ^2.0.2 - flutter_blue_plus: ^1.3.1 + flutter_blue_plus: ^1.29.1 rxdart: ^0.27.6 logging: ^1.1.0