Commit 5c6113e3 authored by Nicolas Richard Walter Boeckh's avatar Nicolas Richard Walter Boeckh 💬

Trying to get BT back

parent 6b4c50f5
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.6.3+1\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.6.3+1\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-02-28 12:41:48.988019","version":"1.14.6"}
\ No newline at end of file
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.6.3+1\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"android":[{"name":"flutter_blue","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_blue-0.6.3+1\\\\","dependencies":[]},{"name":"geolocator","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\geolocator-5.2.1\\\\","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_api_availability-2.0.2\\\\","dependencies":[]},{"name":"location_permissions","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\location_permissions-2.0.4+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.0\\\\","dependencies":[]},{"name":"permission_handler","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\permission_handler-4.2.0+hotfix.3\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"macos":[{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.2.0\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"geolocator","dependencies":["google_api_availability","location_permissions"]},{"name":"google_api_availability","dependencies":[]},{"name":"location_permissions","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"shared_preferences","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-03-04 16:11:15.514195","version":"1.15.4-pre.268"}
\ No newline at end of file
......@@ -26,7 +26,13 @@ Dates are in the sensible `DD/MM/YYYY` format.
## Unreleased
## [0.0.2] - current
## [0.0.3] - current
### [0.0.3] Summary
Add the data transmission to server and initial Location service.
## [0.0.2] - 25/02/2020
### [0.0.2] Summary
......
# Collection of thoughts and general development process
## [0.0.3] - future
## [0.0.3] - current
Most of the UI updates can be based upon stream builder, will limit redraws and conserve.
IE. Battery value recuperated every 5 seconds via platform channel and if different than the one contained in the sink, add it to the sink.
Same concept for PM data.
Build upon data to transmit to the server, then implement post request to transmit data every minute if possible, also not exceed a certain amount, also also cache data.
### [0.0.3] Resources
## [0.0.2] - current
- [Article about POST requests](https://codeburst.io/quick-tip-how-to-make-http-requests-in-dart-53fc407daf31)
- [`http` dart package](https://pub.dev/packages/http)
## [0.0.2] - 25/02/2020
The idea for BLE is to use Platform specific code, ie `Platform channels`...
| Platform Specific | Cross OS |
| ---------------------------- | ----------------------------:|
| Stay Alive ✅ And | Scan environment ✅ |
| Stay Alive ✅ | Scan environment ✅ |
| | Scan named MAC addresses ✅ |
| | Connect to device ✅ |
| Get Battery level ✅ | Read data stream ✅ |
......
enum BluetoothConnectionStatus {
BTSTATUS_SETTING_MTU, // BLUE
BTSTATUS_DISCOVERING_SERVICES, // YELLOW
BTSTATUS_GETTING_CHARACTERISTICS, // ORANGE
BTSTATUS_STREAMING, // GREEN
BTSTATUS_NOT_STREAMING // RED
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter_blue/flutter_blue.dart';
import 'package:kotlin_flavor/scope_functions.dart';
import 'package:logair_application/enums/bluetooth_connection_status.dart';
import 'package:logair_application/handlers/data_handler.dart';
import 'package:logair_application/services/wake_service.dart';
......@@ -20,8 +21,6 @@ class BTLEHandler {
static final BTLEHandler _singleton = new BTLEHandler._internal();
static bool wakeServiceActive = false;
static bool serviceRegistered = false;
static bool characteristicRegistered = false;
BluetoothCharacteristic _characteristic;
......@@ -34,6 +33,8 @@ class BTLEHandler {
FlutterBlue fblueInstance = FlutterBlue.instance;
BluetoothConnectionStatus _bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_NOT_STREAMING;
/// [Stream] that tracks when the app is connected to the [BluetoothDevice]
Stream<bool> isDeviceConnected() async* {
......@@ -68,6 +69,7 @@ class BTLEHandler {
Future<bool> setupListener() async {
if (_characteristic != null) {
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_STREAMING;
_characteristic.value.transform(
new StreamTransformer.fromHandlers(
handleData: (List<int> list, EventSink<List<int>> sink) {
......@@ -78,9 +80,19 @@ class BTLEHandler {
}
)
).listen((data) => DataHandler().addData(data));
print("RETURNS");
return true;
} else
} else {
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_STREAMING;
return false;
}
}
Stream<BluetoothConnectionStatus> getConnectionStatus() async* {
while (true) {
yield _bluetoothConnectionStatus;
await Future.delayed(Duration(seconds: 2));
}
}
/// Makes the phone connect to the [BluetoothDevice] and initiate [BluetoothService] discovery.
......@@ -93,9 +105,14 @@ class BTLEHandler {
asyncConnection() async {
await this._device.connect();
if (Platform.isAndroid)
if (Platform.isAndroid) {
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_SETTING_MTU;
await this._device.requestMtu(517);
}
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_DISCOVERING_SERVICES;
await this._device.discoverServices();
this._device.services.map((event) => print);
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_GETTING_CHARACTERISTICS;
await setupCharacteristics();
await setupListener();
}
......@@ -105,6 +122,8 @@ class BTLEHandler {
await _characteristic.setNotifyValue(false);
_characteristic = null;
_device = null;
_bluetoothConnectionStatus = BluetoothConnectionStatus.BTSTATUS_NOT_STREAMING;
return it.disconnect();
});
......
import 'dart:async';
import 'package:geolocator/geolocator.dart';
import 'package:logair_application/services/permission_service.dart';
class PositionHandler {
/// [Singleton]() instantiation factory.
......@@ -21,11 +22,26 @@ class PositionHandler {
LocationOptions locationOptions = LocationOptions(accuracy: LocationAccuracy.high, distanceFilter: 10);
Stream<GeolocationStatus> getGeolocationStatus() async* {
while (true) {
yield _geolocationStatus;
await Future.delayed(Duration(seconds: 2));
}
}
Position getLastPosition() => _lastPosition;
/*
Stream<Position> getCurrentOrLastPosition() async* {
while (true) {
Position currentPosition;
print("HELLO");
if (!_permissionChecked) {
_geolocationStatus = await _geolocator.checkGeolocationPermissionStatus();
if (_geolocationStatus != GeolocationStatus.granted) {
await PermissionService().requestLocationPermission();
await PermissionService().requestBackgroundLocationPermission();
await PermissionService().requestFineLocationPermission();
}
_geolocationStatus = await _geolocator.checkGeolocationPermissionStatus();
_permissionChecked = true;
}
......@@ -35,11 +51,6 @@ class PositionHandler {
if (currentPosition != null)
_lastPosition = currentPosition;
if (currentPosition != null)
print ('Position : ${currentPosition.latitude}, ${currentPosition.longitude}');
print(_geolocationStatus);
if (currentPosition != null)
yield currentPosition;
else if (currentPosition == null && _lastPosition != null)
......@@ -50,6 +61,7 @@ class PositionHandler {
await Future.delayed(Duration(milliseconds: 900));
}
}
*/
}
\ No newline at end of file
......@@ -25,9 +25,9 @@ class PermissionService {
return granted;
}
Future<bool> _requestLocationPermission({Function onPermissionDenied}) async => _requestPermission(PermissionGroup.location, onPermissionDenied: onPermissionDenied);
Future<bool> requestLocationPermission({Function onPermissionDenied}) async => _requestPermission(PermissionGroup.location, onPermissionDenied: onPermissionDenied);
Future<bool> _requestFineLocationPermission({Function onPermissionDenied}) async => _requestPermission(PermissionGroup.locationWhenInUse, onPermissionDenied: onPermissionDenied);
Future<bool> requestFineLocationPermission({Function onPermissionDenied}) async => _requestPermission(PermissionGroup.locationWhenInUse, onPermissionDenied: onPermissionDenied);
Future<bool> _requestBackgroundLocationPermission({Function onPermissionDenied}) async => _requestPermission(PermissionGroup.locationAlways, onPermissionDenied: onPermissionDenied);
Future<bool> requestBackgroundLocationPermission({Function onPermissionDenied}) async => _requestPermission(PermissionGroup.locationAlways, onPermissionDenied: onPermissionDenied);
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:geolocator/geolocator.dart';
import 'package:logair_application/enums/bluetooth_connection_status.dart';
import 'package:logair_application/handlers/bluetooth_le_handler.dart';
import 'package:logair_application/handlers/data_handler.dart';
......@@ -64,6 +65,7 @@ class DataWidget extends StatelessWidget {
onPressed: () => DataHandler().doPrint(),
child: Text('Print Data Set'),
),
/*
StreamBuilder<Position>(
stream: PositionHandler().getCurrentOrLastPosition(),
builder: (context, snapshot) {
......@@ -74,6 +76,13 @@ class DataWidget extends StatelessWidget {
else
return Text('Null data');
},
),*/
StreamBuilder<BluetoothConnectionStatus>(
stream: BTLEHandler().getConnectionStatus(),
builder: (context, snapshot) {
BluetoothConnectionStatus data = snapshot.data;
return Text(data.toString());
},
),
]
),
......
......@@ -19,7 +19,7 @@ dependencies:
provider: null
geolocator: ^5.2.1
flutter_map: ^0.8.2
flutter_blue: ^0.6.3+1
flutter_blue: 0.6.3+1
permission_handler: ^4.2.0+hotfix.3
get_it: ^3.1.0
shared_preferences: ^0.4.3
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment