Weight scale in progress

dev_3.3_BLE
haroon amjad 3 years ago
parent aad249297c
commit 3f767f738a

@ -20,8 +20,8 @@ var PACKAGES_ORDERS = '/api/orders';
var PACKAGES_ORDER_HISTORY = '/api/orders/items'; var PACKAGES_ORDER_HISTORY = '/api/orders/items';
var PACKAGES_TAMARA_OPT = '/api/orders/paymentoptions/tamara'; var PACKAGES_TAMARA_OPT = '/api/orders/paymentoptions/tamara';
// var BASE_URL = 'http://10.50.100.198:2018/'; // var BASE_URL = 'http://10.50.100.198:2018/';
var BASE_URL = 'https://uat.hmgwebservices.com/'; // var BASE_URL = 'https://uat.hmgwebservices.com/';
// var BASE_URL = 'https://hmgwebservices.com/'; var BASE_URL = 'https://hmgwebservices.com/';
// var BASE_URL = 'https://orash.cloudsolutions.com.sa/'; // var BASE_URL = 'https://orash.cloudsolutions.com.sa/';
// var BASE_URL = 'https://vidauat.cloudsolutions.com.sa/'; // var BASE_URL = 'https://vidauat.cloudsolutions.com.sa/';

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/uitl/ble_utils.dart'; import 'package:diplomaticquarterapp/uitl/ble_utils.dart';
import 'package:diplomaticquarterapp/uitl/bluetooth_off.dart'; import 'package:diplomaticquarterapp/uitl/bluetooth_off.dart';
@ -20,17 +22,19 @@ class _ECG_BLEState extends State<ECG_BLE> {
BluetoothCharacteristic ecgWriteCharacteristic; BluetoothCharacteristic ecgWriteCharacteristic;
StreamSubscription bleDevicesStream;
@override @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
if (bleDevicesStream != null) bleDevicesStream.cancel();
if (currentConnectedDevice != null) currentConnectedDevice.disconnect(); if (currentConnectedDevice != null) currentConnectedDevice.disconnect();
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
FlutterBluePlus.setLogLevel(LogLevel.verbose, color:false); FlutterBluePlus.setLogLevel(LogLevel.verbose, color: false);
} }
@override @override
@ -93,14 +97,14 @@ class _ECG_BLEState extends State<ECG_BLE> {
connectionStatus = "Connecting..."; connectionStatus = "Connecting...";
}); });
FlutterBluePlus.startScan(timeout: const Duration(seconds: 5), androidUsesFineLocation: false).then((value) { bleDevicesStream = FlutterBluePlus.scanResults.listen((results) {
List<ScanResult> blueToothDevices = []; List<ScanResult> blueToothDevices = results;
// List<ScanResult> blueToothDevices = value;
blueToothDevices.forEach((element) async { blueToothDevices.forEach((element) async {
if (element.device.localName.isNotEmpty) { if (element.device.localName.isNotEmpty) {
if (element.device.localName.toLowerCase() == "pm101897") { if (element.device.localName.toLowerCase() == "pm101897") {
bleDevicesStream.cancel();
element.device.connectionState.listen((BluetoothConnectionState state) async { element.device.connectionState.listen((BluetoothConnectionState state) async {
if(mounted) { if (mounted) {
setState(() { setState(() {
connectionStatus = state.toString(); connectionStatus = state.toString();
}); });
@ -110,7 +114,16 @@ class _ECG_BLEState extends State<ECG_BLE> {
// Note: you must always re-discover services after disconnection! // Note: you must always re-discover services after disconnection!
} }
if (state == BluetoothConnectionState.connected) { if (state == BluetoothConnectionState.connected) {
if (FlutterBluePlus.isScanningNow) {
FlutterBluePlus.stopScan();
}
currentConnectedDevice = element.device; currentConnectedDevice = element.device;
// currentConnectedDevice.clearGattCache();
// currentConnectedDevice.requestConnectionPriority(connectionPriorityRequest: ConnectionPriority.high);
// currentConnectedDevice.requestMtu(512);
// currentConnectedDevice.mtu.first.then((value) {
// print("MTU Size: $value");
// });
List<BluetoothService> services = await element.device.discoverServices(); List<BluetoothService> services = await element.device.discoverServices();
services.forEach((service) { services.forEach((service) {
if (service.serviceUuid.toString().toLowerCase() == BLEUtils.ECG_SERVICE) { if (service.serviceUuid.toString().toLowerCase() == BLEUtils.ECG_SERVICE) {
@ -122,13 +135,13 @@ class _ECG_BLEState extends State<ECG_BLE> {
print("onValueReceived Stream"); print("onValueReceived Stream");
print(event); print(event);
}); });
await characteristic.setNotifyValue(true); if (!characteristic.isNotifying) await characteristic.setNotifyValue(true);
} }
if (characteristic.characteristicUuid.toString().toLowerCase() == BLEUtils.ECG_WRITE_CHARACTERISTIC) { if (characteristic.characteristicUuid.toString().toLowerCase() == BLEUtils.ECG_WRITE_CHARACTERISTIC) {
print(characteristic.characteristicUuid); print("Write Characteristic: ${characteristic.characteristicUuid}");
ecgWriteCharacteristic = characteristic; ecgWriteCharacteristic = characteristic;
ecgWriteCharacteristic.write([0x90], allowLongWrite: true); await ecgWriteCharacteristic.write([0x83]);
} }
}); });
return true; return true;
@ -142,6 +155,9 @@ class _ECG_BLEState extends State<ECG_BLE> {
} }
}); });
}); });
FlutterBluePlus.startScan(timeout: const Duration(seconds: 15), androidUsesFineLocation: false).then((value) {
print("Scan Finished");
});
} }
} }
} }

@ -23,4 +23,9 @@ class BLEUtils {
static const String BLOOD_GLUCOSE_SERVICE = "0000fff0-0000-1000-8000-00805f9b34fb"; static const String BLOOD_GLUCOSE_SERVICE = "0000fff0-0000-1000-8000-00805f9b34fb";
static const String BLOOD_GLUCOSE_CHARACTERISTIC = "0000fff4-0000-1000-8000-00805f9b34fb"; static const String BLOOD_GLUCOSE_CHARACTERISTIC = "0000fff4-0000-1000-8000-00805f9b34fb";
// Weight Scale
static const String WEIGHT_MEASUREMENT_CHARACTERISTIC_FFF1 = "0000fff1-0000-1000-8000-00805f9b34fb";
static const String WEIGHT_MEASUREMENT_CHARACTERISTIC_FFF2 = "0000fff2-0000-1000-8000-00805f9b34fb";
static const String WEIGHT_MEASUREMENT_CHARACTERISTIC_FFF3 = "0000fff3-0000-1000-8000-00805f9b34fb";
static const String WEIGHT_MEASUREMENT_SERVICE = "0000fff0-0000-1000-8000-00805f9b34fb";
} }
Loading…
Cancel
Save