Weight scale in progress

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

@ -20,8 +20,8 @@ var PACKAGES_ORDERS = '/api/orders';
var PACKAGES_ORDER_HISTORY = '/api/orders/items';
var PACKAGES_TAMARA_OPT = '/api/orders/paymentoptions/tamara';
// var BASE_URL = 'http://10.50.100.198:2018/';
var BASE_URL = 'https://uat.hmgwebservices.com/';
// var BASE_URL = 'https://hmgwebservices.com/';
// var BASE_URL = 'https://uat.hmgwebservices.com/';
var BASE_URL = 'https://hmgwebservices.com/';
// var BASE_URL = 'https://orash.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/uitl/ble_utils.dart';
import 'package:diplomaticquarterapp/uitl/bluetooth_off.dart';
@ -20,17 +22,19 @@ class _ECG_BLEState extends State<ECG_BLE> {
BluetoothCharacteristic ecgWriteCharacteristic;
StreamSubscription bleDevicesStream;
@override
void dispose() {
super.dispose();
if (bleDevicesStream != null) bleDevicesStream.cancel();
if (currentConnectedDevice != null) currentConnectedDevice.disconnect();
}
@override
void initState() {
super.initState();
FlutterBluePlus.setLogLevel(LogLevel.verbose, color:false);
FlutterBluePlus.setLogLevel(LogLevel.verbose, color: false);
}
@override
@ -93,14 +97,14 @@ class _ECG_BLEState extends State<ECG_BLE> {
connectionStatus = "Connecting...";
});
FlutterBluePlus.startScan(timeout: const Duration(seconds: 5), androidUsesFineLocation: false).then((value) {
List<ScanResult> blueToothDevices = [];
// List<ScanResult> blueToothDevices = value;
bleDevicesStream = FlutterBluePlus.scanResults.listen((results) {
List<ScanResult> blueToothDevices = results;
blueToothDevices.forEach((element) async {
if (element.device.localName.isNotEmpty) {
if (element.device.localName.toLowerCase() == "pm101897") {
bleDevicesStream.cancel();
element.device.connectionState.listen((BluetoothConnectionState state) async {
if(mounted) {
if (mounted) {
setState(() {
connectionStatus = state.toString();
});
@ -110,7 +114,16 @@ class _ECG_BLEState extends State<ECG_BLE> {
// Note: you must always re-discover services after disconnection!
}
if (state == BluetoothConnectionState.connected) {
if (FlutterBluePlus.isScanningNow) {
FlutterBluePlus.stopScan();
}
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();
services.forEach((service) {
if (service.serviceUuid.toString().toLowerCase() == BLEUtils.ECG_SERVICE) {
@ -122,13 +135,13 @@ class _ECG_BLEState extends State<ECG_BLE> {
print("onValueReceived Stream");
print(event);
});
await characteristic.setNotifyValue(true);
if (!characteristic.isNotifying) await characteristic.setNotifyValue(true);
}
if (characteristic.characteristicUuid.toString().toLowerCase() == BLEUtils.ECG_WRITE_CHARACTERISTIC) {
print(characteristic.characteristicUuid);
print("Write Characteristic: ${characteristic.characteristicUuid}");
ecgWriteCharacteristic = characteristic;
ecgWriteCharacteristic.write([0x90], allowLongWrite: true);
await ecgWriteCharacteristic.write([0x83]);
}
});
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_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